HHH-7371 Natural-id: ObjectNotFoundException when found entity is marked as deleted
This commit is contained in:
parent
8fa530a247
commit
4fe75d5a09
|
@ -45,6 +45,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.persistence.EntityNotFoundException;
|
||||||
|
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
|
@ -64,6 +66,7 @@ import org.hibernate.LockOptions;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.NaturalIdLoadAccess;
|
import org.hibernate.NaturalIdLoadAccess;
|
||||||
import org.hibernate.ObjectDeletedException;
|
import org.hibernate.ObjectDeletedException;
|
||||||
|
import org.hibernate.ObjectNotFoundException;
|
||||||
import org.hibernate.Query;
|
import org.hibernate.Query;
|
||||||
import org.hibernate.QueryException;
|
import org.hibernate.QueryException;
|
||||||
import org.hibernate.ReplicationMode;
|
import org.hibernate.ReplicationMode;
|
||||||
|
@ -2605,7 +2608,16 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
|
||||||
if ( entityId == null ) {
|
if ( entityId == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return this.getIdentifierLoadAccess().load( entityId );
|
try {
|
||||||
|
return this.getIdentifierLoadAccess().load( entityId );
|
||||||
|
}
|
||||||
|
catch (EntityNotFoundException enf) {
|
||||||
|
// OK
|
||||||
|
}
|
||||||
|
catch (ObjectNotFoundException nf) {
|
||||||
|
// OK
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2663,7 +2675,16 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc
|
||||||
if ( entityId == null ) {
|
if ( entityId == null ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return this.getIdentifierLoadAccess().load( entityId );
|
try {
|
||||||
|
return this.getIdentifierLoadAccess().load( entityId );
|
||||||
|
}
|
||||||
|
catch (EntityNotFoundException enf) {
|
||||||
|
// OK
|
||||||
|
}
|
||||||
|
catch (ObjectNotFoundException nf) {
|
||||||
|
// OK
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,6 +161,48 @@ public class ImmutableEntityNaturalIdTest extends BaseCoreFunctionalTestCase {
|
||||||
s.close();
|
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
|
@Override
|
||||||
protected Class[] getAnnotatedClasses() {
|
protected Class[] getAnnotatedClasses() {
|
||||||
return new Class[] {
|
return new Class[] {
|
||||||
|
|
Loading…
Reference in New Issue