From: <no...@at...> - 2006-05-17 22:25:14
|
[ http://opensource.atlassian.com/projects/hibernate/browse/EJB-98?pag= e=3Dall ] Micha=C5=82 Borowiecki updated EJB-98: --------------------------------- Attachment: DefaultLoadEventListener.patch The DefaultLoadEventListener.loadFromSessionCache method throws ObjectDelet= edException if the option checkDeleted =3D=3D true and the entity is DELETE= D or GONE. One way to fix this bug is to make it return null instead of throwing the e= xception. I have examined the usages of this class and I think returning null here is= the reasonable thing to do. It will still be consistent with the API doc for this method, which merely = states that its status is checked: "If checkDeleted was set to true, then if the entity is found in the sessio= n-level cache, it's current status within the session cache is checked to s= ee if it has previously been scheduled for deletion." The method createProxyIfNecessary should behave the same way.=20 I attach a patch modifying both methods to return null in this case instead= of throwing the exception. > EntityManager.find() throws an org.hibernate.ObjectDeletedException if yo= u find something deleted in the same TXA > -------------------------------------------------------------------------= ---------------------------------------- > > Key: EJB-98 > URL: http://opensource.atlassian.com/projects/hibernate/browse/E= JB-98 > Project: Hibernate Entity Manager > Type: Bug > Components: EntityManager > Versions: 3.1beta5 > Environment: Java 1.5.06/junit3.8.1,hibernate 3.1, entity manager 3.1bet= a5, hsqldb 1.8.01 > Reporter: Steve Loughran > Fix For: 3.2.0 > Attachments: DefaultLoadEventListener.patch > > > I have a junit test case that persists something, finds it, then deletes = it and tries to find again. > Second time round, find() fails with an ObjectDeletedException. This is t= he semantics of Session.load(), not EntityManager.find(), which is meant to= return null if something cannot be found: > public void testDeleteAndFindFailsWrong() throws Exception { > Event event =3D createTestEvent(); > String key =3D event.getKey(); > EntityTransaction transaction =3D null; > try { > transaction =3D manager.getTransaction(); > transaction.begin(); > manager.persist(event); > Event e2 =3D manager.find(Event.class, key); > assertEquals(event, e2); > manager.remove(e2); > try { > e2 =3D manager.find(Event.class, key); > assertNull("The spec says that find should return null he= re", e2); > } catch (ObjectDeletedException e) { > fail("This is not in the spec"+e); > } > } finally { > rollback(transaction); > } > } =20 --=20 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 |