HHH-3868 Fix null pointer exception on merge of entity with transient component

This commit is contained in:
jmoore 2014-10-10 11:54:11 +02:00 committed by Andrea Boriero
parent 00eaed6dfe
commit b197f6a643
2 changed files with 17 additions and 0 deletions

View File

@ -680,6 +680,9 @@ public class StatefulPersistenceContext implements PersistenceContext {
@Override @Override
public Object proxyFor(Object impl) throws HibernateException { public Object proxyFor(Object impl) throws HibernateException {
final EntityEntry e = getEntry( impl ); final EntityEntry e = getEntry( impl );
if ( e == null ) {
return impl;
}
return proxyFor( e.getPersister(), e.getEntityKey(), impl ); return proxyFor( e.getPersister(), e.getEntityKey(), impl );
} }

View File

@ -31,6 +31,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import org.hibernate.Query; import org.hibernate.Query;
import org.hibernate.Session; import org.hibernate.Session;
@ -39,6 +40,7 @@ import org.hibernate.test.annotations.embedded.FloatLeg.RateIndex;
import org.hibernate.test.annotations.embedded.Leg.Frequency; import org.hibernate.test.annotations.embedded.Leg.Frequency;
import org.hibernate.test.util.SchemaUtil; import org.hibernate.test.util.SchemaUtil;
import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test; import org.junit.Test;
@ -517,6 +519,18 @@ public class EmbeddedTest extends BaseCoreFunctionalTestCase {
s.close(); s.close();
} }
@Test
@TestForIssue(jiraKey = "HHH-3868")
public void testTransientMergeComponentParent() {
Session s = openSession();
Transaction tx = s.beginTransaction();
Book b = new Book();
b.setIsbn( UUID.randomUUID().toString() );
b.setSummary( new Summary() );
b = (Book) session.merge( b );
tx.commit();
}
@Override @Override
protected Class[] getAnnotatedClasses() { protected Class[] getAnnotatedClasses() {
return new Class[]{ return new Class[]{