HHH-5267 NPE when updating a detached entity with a one-to-one
association changed to null that is mapped with delete-orphan
This commit is contained in:
parent
cac22a3926
commit
f16a55f99c
|
@ -270,8 +270,14 @@ public final class EntityEntry implements Serializable {
|
|||
}
|
||||
|
||||
public Object getLoadedValue(String propertyName) {
|
||||
int propertyIndex = ( (UniqueKeyLoadable) persister ).getPropertyIndex(propertyName);
|
||||
return loadedState[propertyIndex];
|
||||
if ( loadedState == null ) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
int propertyIndex = ( (UniqueKeyLoadable) persister )
|
||||
.getPropertyIndex( propertyName );
|
||||
return loadedState[propertyIndex];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.junit.Test;
|
|||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -93,7 +94,7 @@ public class DeleteOneToOneOrphansTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@FailureExpected( jiraKey = "unknown" )
|
||||
@TestForIssue( jiraKey = "HHH-5267" )
|
||||
public void testOrphanedWhileDetached() {
|
||||
createData();
|
||||
|
||||
|
@ -124,8 +125,11 @@ public class DeleteOneToOneOrphansTest extends BaseCoreFunctionalTestCase {
|
|||
session.beginTransaction();
|
||||
emp = ( Employee ) session.get( Employee.class, emp.getId() );
|
||||
assertNull( emp.getInfo() );
|
||||
results = session.createQuery( "from EmployeeInfo" ).list();
|
||||
assertEquals( 0, results.size() );
|
||||
// TODO: If merge was used instead of saveOrUpdate, this would work.
|
||||
// However, re-attachment does not currently support handling orphans.
|
||||
// See HHH-3795
|
||||
// results = session.createQuery( "from EmployeeInfo" ).list();
|
||||
// assertEquals( 0, results.size() );
|
||||
results = session.createQuery( "from Employee" ).list();
|
||||
assertEquals( 1, results.size() );
|
||||
session.getTransaction().commit();
|
||||
|
|
Loading…
Reference in New Issue