[hibernate-issues] [Hibernate-JIRA] Created: (HHH-6997) Acquiring a lock on merging an entity
Vincent MATHON (JIRA)
noreply at atlassian.com
Wed Jan 25 05:49:09 EST 2012
Acquiring a lock on merging an entity
-------------------------------------
Key: HHH-6997
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6997
Project: Hibernate ORM
Issue Type: New Feature
Components: core
Affects Versions: 4.0.1
Environment: DB2, Linux, JPA 2, JDK 1.6_29
Reporter: Vincent MATHON
I would like to acquire a pessimistic lock after a merge:
public T makePersistent(T entity, boolean lock) {
T mergedEntity = getEntityManager().merge(entity);
if (lock) {
em.flush();// sadly enough, this is necessary in case of insert
em.lock(mergedEntity, javax.persistence.LockModeType.PESSIMISTIC_READ);
}
return mergedObject;
}
I must trigger a flush to avoid an OptimisticLockException (similar to https://hibernate.onjira.com/browse/HHH-4177) if the entity does not exist yet in database..
It is pity that JPA does not allow for locking in the merge method signature... Couldn't Hibernate be smart enough to not throw any exception in the lock method, nor try to select for update if the mergedEntity is flagged as an entity to insert ?
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list