From c60c97b468bea246906cbd11b28168ffa3e761c6 Mon Sep 17 00:00:00 2001 From: jmoore Date: Fri, 10 Oct 2014 11:54:11 +0200 Subject: [PATCH] HHH-3868 Fix null pointer exception on merge of entity with transient component --- .../internal/StatefulPersistenceContext.java | 3 +++ .../test/annotations/embedded/EmbeddedTest.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java index 5ea6e2e911..4d37e7cb20 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java @@ -680,6 +680,9 @@ public class StatefulPersistenceContext implements PersistenceContext { @Override public Object proxyFor(Object impl) throws HibernateException { final EntityEntry e = getEntry( impl ); + if ( e == null ) { + return impl; + } return proxyFor( e.getPersister(), e.getEntityKey(), impl ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java index 267d99f287..c9053df23b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; +import java.util.UUID; import org.junit.Test; @@ -37,6 +38,7 @@ import org.hibernate.Transaction; import org.hibernate.test.annotations.embedded.FloatLeg.RateIndex; import org.hibernate.test.annotations.embedded.Leg.Frequency; import org.hibernate.test.util.SchemaUtil; +import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import static org.junit.Assert.assertEquals; @@ -517,6 +519,18 @@ public class EmbeddedTest extends BaseCoreFunctionalTestCase { 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 protected Class[] getAnnotatedClasses() { return new Class[]{