Hello,
I have a problem with the EntityManager.merge() function.
I set a property value of an entity (statement) with an other entity (newSingleConstraint).
newSingleValue is already persisted. I do this myself (no use of cascade because sometimes the newSingleValue is already in database).
The statement update don't throw exception. And when i try to reload statement the value i have set before is a null value.
I check with the Explorer, the statement has a null value on the property and the newSingleValue is present.
The entity manager don't link the newSingleValue to the statement when i update.
The statement's property is typed by a class that is a superclass of the newSingleValue.
This the chain of call that don't work:
@Component
public class ProtocolsEditorServiceImplProto implements ProtocolsEditorService {
....
public void putConstraintInStatement(ConstraintForm constraint,
String elementType, Long statementId) throws Exception {
.....
ergoManager.createErgoClass(newSingleConstraint);
// if not already exist in database.
statement.setConstraintForAttribute(elementType, newSingleConstraint);
//set a property of statement with the newSingleConstraint
ergoManager.updateErgoClass(statement);
....
}
}
ergoManager implementation:
@Component
@Transactional
public class ErgoManagerImpl implements IErgoManager {
public void createErgoClass(ERGOClass ergoClass)
throws EntryAlreadyExistInDaoException, ServiceException {
ergoDao.saveErgoClass(ergoClass);
}
public void updateErgoClass(ERGOClass ergoClass) throws ServiceException {
ergoDao.updateErgoClass(ergoClass);
}
}
ergoDao implementation:
@Repository
public class ErgoDaoJpa implements IErgoDao {
@PersistenceContext
private EntityManager entityManager;
public void saveErgoClass(ERGOClass ergoClass)
throws EntryAlreadyExistException, DaoException {
entityManager.persist(ergoClass);
}
public void updateErgoClass(ERGOClass ergoClass) throws DaoException {
entityManager.merge(ergoClass);
}
}
Thanks for your help.
Sorry for my bad english :)