HHH-7371 Natural-id: ObjectNotFoundException when found entity is marked as deleted
This commit is contained in:
parent
a608bc3b87
commit
77512d01a7
|
@ -45,6 +45,8 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
|
@ -64,6 +66,7 @@ import org.hibernate.LockOptions;
|
|||
import org.hibernate.MappingException;
|
||||
import org.hibernate.NaturalIdLoadAccess;
|
||||
import org.hibernate.ObjectDeletedException;
|
||||
import org.hibernate.ObjectNotFoundException;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.QueryException;
|
||||
import org.hibernate.ReplicationMode;
|
||||
|
@ -2583,7 +2586,16 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
|
|||
if ( entityId == null ) {
|
||||
return null;
|
||||
}
|
||||
return this.getIdentifierLoadAccess().load( entityId );
|
||||
try {
|
||||
return this.getIdentifierLoadAccess().load( entityId );
|
||||
}
|
||||
catch (EntityNotFoundException enf) {
|
||||
// OK
|
||||
}
|
||||
catch (ObjectNotFoundException nf) {
|
||||
// OK
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2641,7 +2653,16 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
|
|||
if ( entityId == null ) {
|
||||
return null;
|
||||
}
|
||||
return this.getIdentifierLoadAccess().load( entityId );
|
||||
try {
|
||||
return this.getIdentifierLoadAccess().load( entityId );
|
||||
}
|
||||
catch (EntityNotFoundException enf) {
|
||||
// OK
|
||||
}
|
||||
catch (ObjectNotFoundException nf) {
|
||||
// OK
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,6 +160,48 @@ public class ImmutableEntityNaturalIdTest extends BaseCoreFunctionalTestCase {
|
|||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-7371" )
|
||||
public void testImmutableNaturalIdLifecycle2() {
|
||||
Building b1 = new Building();
|
||||
b1.setName( "Computer Science" );
|
||||
b1.setAddress( "1210 W. Dayton St." );
|
||||
b1.setCity( "Madison" );
|
||||
b1.setState( "WI" );
|
||||
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
s.persist( b1 );
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
NaturalIdLoadAccess naturalIdLoader = s.byNaturalId( Building.class );
|
||||
naturalIdLoader.using( "address", "1210 W. Dayton St." ).using( "city", "Madison" ).using( "state", "WI" );
|
||||
Building building = (Building) naturalIdLoader.getReference();
|
||||
assertNotNull( building );
|
||||
|
||||
s.delete( building );
|
||||
building = (Building) naturalIdLoader.load();
|
||||
//org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [org.hibernate.test.naturalid.immutableentity.Building#1]
|
||||
// at org.hibernate.internal.SessionFactoryImpl$1$1.handleEntityNotFound(SessionFactoryImpl.java:247)
|
||||
// at org.hibernate.event.internal.DefaultLoadEventListener.returnNarrowedProxy(DefaultLoadEventListener.java:282)
|
||||
// at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:248)
|
||||
// at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:148)
|
||||
// at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1079)
|
||||
// at org.hibernate.internal.SessionImpl.access$13(SessionImpl.java:1075)
|
||||
// at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2425)
|
||||
// at org.hibernate.internal.SessionImpl$NaturalIdLoadAccessImpl.load(SessionImpl.java:2586)
|
||||
// at org.hibernate.test.naturalid.immutableentity.ImmutableEntityNaturalIdTest.testImmutableNaturalIdLifecycle2(ImmutableEntityNaturalIdTest.java:188)
|
||||
|
||||
assertNull( building );
|
||||
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
|
|
Loading…
Reference in New Issue