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:
brmeyer 2012-10-31 13:54:10 -04:00
parent 1b5088a911
commit 3847ebb478
2 changed files with 15 additions and 5 deletions

View File

@ -270,8 +270,14 @@ public final class EntityEntry implements Serializable {
} }
public Object getLoadedValue(String propertyName) { public Object getLoadedValue(String propertyName) {
int propertyIndex = ( (UniqueKeyLoadable) persister ).getPropertyIndex(propertyName); if ( loadedState == null ) {
return loadedState[propertyIndex]; return null;
}
else {
int propertyIndex = ( (UniqueKeyLoadable) persister )
.getPropertyIndex( propertyName );
return loadedState[propertyIndex];
}
} }
/** /**

View File

@ -29,6 +29,7 @@ import org.junit.Test;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.testing.FailureExpected; import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -93,7 +94,7 @@ public class DeleteOneToOneOrphansTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
@FailureExpected( jiraKey = "unknown" ) @TestForIssue( jiraKey = "HHH-5267" )
public void testOrphanedWhileDetached() { public void testOrphanedWhileDetached() {
createData(); createData();
@ -124,8 +125,11 @@ public class DeleteOneToOneOrphansTest extends BaseCoreFunctionalTestCase {
session.beginTransaction(); session.beginTransaction();
emp = ( Employee ) session.get( Employee.class, emp.getId() ); emp = ( Employee ) session.get( Employee.class, emp.getId() );
assertNull( emp.getInfo() ); assertNull( emp.getInfo() );
results = session.createQuery( "from EmployeeInfo" ).list(); // TODO: If merge was used instead of saveOrUpdate, this would work.
assertEquals( 0, results.size() ); // 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(); results = session.createQuery( "from Employee" ).list();
assertEquals( 1, results.size() ); assertEquals( 1, results.size() );
session.getTransaction().commit(); session.getTransaction().commit();