diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/ops/GetLoadTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/ops/GetLoadTest.java index 8265abd159..2b7a55463e 100755 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/ops/GetLoadTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/ops/GetLoadTest.java @@ -8,12 +8,15 @@ package org.hibernate.jpa.test.ops; import java.util.Map; import javax.persistence.EntityManager; +import javax.persistence.EntityNotFoundException; import org.hibernate.Hibernate; import org.hibernate.Session; import org.hibernate.cfg.Environment; import org.hibernate.dialect.AbstractHANADialect; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; + +import org.hibernate.testing.FailureExpected; import org.hibernate.testing.SkipForDialect; import org.hibernate.testing.TestForIssue; import org.junit.Test; @@ -174,6 +177,108 @@ public class GetLoadTest extends BaseEntityManagerFunctionalTestCase { em.close(); } + @Test + @TestForIssue( jiraKey = "HHH-12034") + @FailureExpected( jiraKey = "HHH-12034" ) + public void testLoadIdNotFound_FieldBasedAccess() { + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); + Session s = ( Session ) em.getDelegate(); + + assertNull( s.get( Workload.class, 999 ) ); + + Workload proxy = s.load( Workload.class, 999 ); + assertFalse( Hibernate.isInitialized( proxy ) ); + + try { + proxy.getId(); + fail( "Should have failed because there is no Workload Entity with id == 999" ); + } + catch (EntityNotFoundException ex) { + // expected + em.getTransaction().rollback(); + } + finally { + em.close(); + } + } + + @Test + @TestForIssue( jiraKey = "HHH-12034") + @FailureExpected( jiraKey = "HHH-12034" ) + public void testReferenceIdNotFound_FieldBasedAccess() { + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); + + assertNull( em.find( Workload.class, 999 ) ); + + Workload proxy = em.getReference( Workload.class, 999 ); + assertFalse( Hibernate.isInitialized( proxy ) ); + + try { + proxy.getId(); + fail( "Should have failed because there is no Workload Entity with id == 999" ); + } + catch (EntityNotFoundException ex) { + // expected + em.getTransaction().rollback(); + } + finally { + em.close(); + } + } + + @Test + @TestForIssue( jiraKey = "HHH-12034") + @FailureExpected( jiraKey = "HHH-12034" ) + public void testLoadIdNotFound_PropertyBasedAccess() { + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); + Session s = ( Session ) em.getDelegate(); + + assertNull( s.get( Employee.class, 999 ) ); + + Employee proxy = s.load( Employee.class, 999 ); + assertFalse( Hibernate.isInitialized( proxy ) ); + + try { + proxy.getId(); + fail( "Should have failed because there is no Employee Entity with id == 999" ); + } + catch (EntityNotFoundException ex) { + // expected + em.getTransaction().rollback(); + } + finally { + em.close(); + } + } + + @Test + @TestForIssue( jiraKey = "HHH-12034") + @FailureExpected( jiraKey = "HHH-12034" ) + public void testReferenceIdNotFound_PropertyBasedAccess() { + EntityManager em = getOrCreateEntityManager(); + em.getTransaction().begin(); + + assertNull( em.find( Employee.class, 999 ) ); + + Employee proxy = em.getReference( Employee.class, 999 ); + assertFalse( Hibernate.isInitialized( proxy ) ); + + try { + proxy.getId(); + fail( "Should have failed because there is no Employee Entity with id == 999" ); + } + catch (EntityNotFoundException ex) { + // expected + em.getTransaction().rollback(); + } + finally { + em.close(); + } + } + @Override @SuppressWarnings( {"unchecked"}) protected void addConfigOptions(Map options) {