HHH-13640 - Add PrepareStatement executed check to LazyToOnesProxyWithoutSubclassesTest
This commit is contained in:
parent
616f549f8c
commit
2bc7fed96e
|
@ -22,6 +22,7 @@ import org.hibernate.boot.SessionFactoryBuilder;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.proxy.HibernateProxy;
|
import org.hibernate.proxy.HibernateProxy;
|
||||||
|
import org.hibernate.stat.Statistics;
|
||||||
|
|
||||||
import org.hibernate.testing.FailureExpected;
|
import org.hibernate.testing.FailureExpected;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
|
@ -31,6 +32,7 @@ import org.junit.After;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
@ -77,16 +79,52 @@ public class LazyToOnesProxyWithSubclassesTest extends BaseNonConfigCoreFunction
|
||||||
|
|
||||||
inSession(
|
inSession(
|
||||||
session -> {
|
session -> {
|
||||||
|
final Statistics stats = sessionFactory().getStatistics();
|
||||||
|
stats.clear();
|
||||||
final OtherEntity otherEntity = session.get( OtherEntity.class, "test1" );
|
final OtherEntity otherEntity = session.get( OtherEntity.class, "test1" );
|
||||||
assertTrue( Hibernate.isPropertyInitialized( otherEntity, "animal" ) );
|
assertTrue( Hibernate.isPropertyInitialized( otherEntity, "animal" ) );
|
||||||
assertFalse( Hibernate.isInitialized( otherEntity.animal ) );
|
assertFalse( Hibernate.isInitialized( otherEntity.animal ) );
|
||||||
assertTrue( HibernateProxy.class.isInstance( otherEntity.animal ) );
|
assertTrue( HibernateProxy.class.isInstance( otherEntity.animal ) );
|
||||||
|
|
||||||
|
assertEquals( 1, stats.getPrepareStatementCount() );
|
||||||
|
|
||||||
Animal animal = session.load( Animal.class, "A Human" );
|
Animal animal = session.load( Animal.class, "A Human" );
|
||||||
assertFalse( Hibernate.isInitialized( animal ) );
|
assertFalse( Hibernate.isInitialized( animal ) );
|
||||||
|
assertEquals( 1, stats.getPrepareStatementCount() );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetInitializeAssociations() {
|
||||||
|
inTransaction(
|
||||||
|
session -> {
|
||||||
|
Human human = new Human( "A Human" );
|
||||||
|
OtherEntity otherEntity = new OtherEntity( "test1" );
|
||||||
|
otherEntity.animal = human;
|
||||||
|
|
||||||
|
session.persist( human );
|
||||||
|
session.persist( otherEntity );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
inSession(
|
||||||
|
session -> {
|
||||||
|
final Statistics stats = sessionFactory().getStatistics();
|
||||||
|
stats.clear();
|
||||||
|
final OtherEntity otherEntity = session.get( OtherEntity.class, "test1" );
|
||||||
|
assertTrue( Hibernate.isPropertyInitialized( otherEntity, "animal" ) );
|
||||||
|
assertFalse( Hibernate.isInitialized( otherEntity.animal ) );
|
||||||
|
assertEquals( 1, stats.getPrepareStatementCount() );
|
||||||
|
|
||||||
|
Animal animal = session.get( Animal.class, "A Human" );
|
||||||
|
assertTrue( Hibernate.isInitialized( animal ) );
|
||||||
|
assertEquals( 2, stats.getPrepareStatementCount() );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testExistingProxyAssociation() {
|
public void testExistingProxyAssociation() {
|
||||||
inTransaction(
|
inTransaction(
|
||||||
|
@ -102,6 +140,8 @@ public class LazyToOnesProxyWithSubclassesTest extends BaseNonConfigCoreFunction
|
||||||
|
|
||||||
inSession(
|
inSession(
|
||||||
session -> {
|
session -> {
|
||||||
|
final Statistics stats = sessionFactory().getStatistics();
|
||||||
|
stats.clear();
|
||||||
final OtherEntity otherEntity = session.get( OtherEntity.class, "test1" );
|
final OtherEntity otherEntity = session.get( OtherEntity.class, "test1" );
|
||||||
assertTrue( Hibernate.isPropertyInitialized( otherEntity, "animal" ) );
|
assertTrue( Hibernate.isPropertyInitialized( otherEntity, "animal" ) );
|
||||||
assertFalse( Hibernate.isInitialized( otherEntity.animal ) );
|
assertFalse( Hibernate.isInitialized( otherEntity.animal ) );
|
||||||
|
@ -109,7 +149,7 @@ public class LazyToOnesProxyWithSubclassesTest extends BaseNonConfigCoreFunction
|
||||||
assertTrue( Hibernate.isPropertyInitialized( otherEntity, "primate" ) );
|
assertTrue( Hibernate.isPropertyInitialized( otherEntity, "primate" ) );
|
||||||
assertFalse( Hibernate.isInitialized( otherEntity.primate ) );
|
assertFalse( Hibernate.isInitialized( otherEntity.primate ) );
|
||||||
assertTrue( HibernateProxy.class.isInstance( otherEntity.primate ) );
|
assertTrue( HibernateProxy.class.isInstance( otherEntity.primate ) );
|
||||||
|
assertEquals( 1, stats.getPrepareStatementCount() );
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -131,6 +171,9 @@ public class LazyToOnesProxyWithSubclassesTest extends BaseNonConfigCoreFunction
|
||||||
|
|
||||||
inSession(
|
inSession(
|
||||||
session -> {
|
session -> {
|
||||||
|
final Statistics stats = sessionFactory().getStatistics();
|
||||||
|
stats.clear();
|
||||||
|
|
||||||
final OtherEntity otherEntity = session.get( OtherEntity.class, "test1" );
|
final OtherEntity otherEntity = session.get( OtherEntity.class, "test1" );
|
||||||
assertTrue( Hibernate.isPropertyInitialized( otherEntity, "animal" ) );
|
assertTrue( Hibernate.isPropertyInitialized( otherEntity, "animal" ) );
|
||||||
assertFalse( Hibernate.isInitialized( otherEntity.animal ) );
|
assertFalse( Hibernate.isInitialized( otherEntity.animal ) );
|
||||||
|
@ -142,6 +185,8 @@ public class LazyToOnesProxyWithSubclassesTest extends BaseNonConfigCoreFunction
|
||||||
assertFalse( Hibernate.isInitialized( otherEntity.human ) );
|
assertFalse( Hibernate.isInitialized( otherEntity.human ) );
|
||||||
// TODO: Should otherEntity.human be a narrowed HibernateProxy or
|
// TODO: Should otherEntity.human be a narrowed HibernateProxy or
|
||||||
// an uninitialized non-HibernateProxy proxy?
|
// an uninitialized non-HibernateProxy proxy?
|
||||||
|
assertEquals( 1, stats.getPrepareStatementCount() );
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -158,7 +203,6 @@ public class LazyToOnesProxyWithSubclassesTest extends BaseNonConfigCoreFunction
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Entity(name = "Animal")
|
@Entity(name = "Animal")
|
||||||
@Table(name = "Animal")
|
@Table(name = "Animal")
|
||||||
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
||||||
|
|
Loading…
Reference in New Issue