[hibernate-issues] [Hibernate-JIRA] Created: (EJB-422) PersistenceException is thrown or not depending on wheter there is @Version annotation
Paweł Szulc (JIRA)
noreply at atlassian.com
Wed Apr 8 04:38:37 EDT 2009
PersistenceException is thrown or not depending on wheter there is @Version annotation
--------------------------------------------------------------------------------------
Key: EJB-422
URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-422
Project: Hibernate Entity Manager
Issue Type: Bug
Components: EntityManager
Environment: discovered on Windowx XP, using JPA with Hibernate implementation
Reporter: Paweł Szulc
Example:
PriorityProjectRef is normal entity class. If we dont use OptimisticLocking for it (there is no @Version) then test that u can see below will pass. Persisting entity with id set to value of existing entitty will throw an exception - PersistenceException.
@Test(expected = PersistenceException.class)
public void testUniqueKey() {
PriorityProjectRef entity = new PriorityProjectRef();
dao.persist(entity);
PriorityProjectRef entity2 = new PriorityProjectRef();
entity2.setId(entity.getId());
dao.persist(entity2);
}
However if we add to our PriorityProjectRef entity class new field annotated with @Version (to use optimistic locking), the test will fail. There will be no PersistenceException thrown. Second entity will be saved, with new id set from the sequence.
In other words:
without @Version - only one entity persisted, PersistenceException thrown
with @Version - two enites persisted (with different IDs), PersistenceException not thrown
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list