1- package  org .hibernate .orm .test .refresh ;
1+ package  org .hibernate .orm .test .bytecode . enhancement . batch ;
22
33import  java .util .ArrayList ;
44import  java .util .List ;
55
6+ import  org .hibernate .Hibernate ;
67import  org .hibernate .annotations .BatchSize ;
78import  org .hibernate .cfg .AvailableSettings ;
89
10+ import  org .hibernate .testing .bytecode .enhancement .extension .BytecodeEnhanced ;
11+ import  org .hibernate .testing .orm .junit .DomainModel ;
912import  org .hibernate .testing .orm .junit .EntityManagerFactoryScope ;
1013import  org .hibernate .testing .orm .junit .JiraKey ;
1114import  org .hibernate .testing .orm .junit .Jpa ;
15+ import  org .hibernate .testing .orm .junit .ServiceRegistry ;
16+ import  org .hibernate .testing .orm .junit .SessionFactory ;
17+ import  org .hibernate .testing .orm .junit .SessionFactoryScope ;
1218import  org .hibernate .testing .orm .junit .Setting ;
19+ import  org .junit .jupiter .api .AfterEach ;
1320import  org .junit .jupiter .api .BeforeEach ;
1421import  org .junit .jupiter .api .Test ;
1522
2532import  jakarta .persistence .OneToOne ;
2633import  jakarta .persistence .Table ;
2734
28- @ Jpa (
35+ import  static  org .assertj .core .api .AssertionsForClassTypes .assertThat ;
36+ 
37+ @ DomainModel (
2938		annotatedClasses  = {
3039				RefreshAndBatchTest .User .class ,
3140				RefreshAndBatchTest .UserInfo .class ,
3241				RefreshAndBatchTest .Phone .class ,
33- 		},
34- 		properties  = {
42+ 		}
43+ 
44+ )
45+ @ SessionFactory 
46+ @ ServiceRegistry (
47+ 		settings  = {
3548				@ Setting (name  = AvailableSettings .DEFAULT_BATCH_FETCH_SIZE , value  = "100" )
3649
3750		}
3851)
3952@ JiraKey ("HHH-18608" )
53+ @ BytecodeEnhanced (runNotEnhancedAsWell  = true )
4054public  class  RefreshAndBatchTest  {
4155
4256	@ BeforeEach 
43- 	public  void  setUp (EntityManagerFactoryScope  scope ) {
57+ 	public  void  setUp (SessionFactoryScope  scope ) {
4458		scope .inTransaction (
4559				session  -> {
4660					UserInfo  info  = new  UserInfo ( "info"  );
@@ -52,14 +66,27 @@ public void setUp(EntityManagerFactoryScope scope) {
5266		);
5367	}
5468
69+ 	@ AfterEach 
70+ 	public  void  tearDown (SessionFactoryScope  scope ) {
71+ 		scope .inTransaction (
72+ 				session  -> {
73+ 					session .createQuery ( "delete User"  ).executeUpdate ();
74+ 					session .createQuery ( "delete Phone"  ).executeUpdate ();
75+ 					session .createQuery ( "delete UserInfo"  ).executeUpdate ();
76+ 				}
77+ 		);
78+ 	}
79+ 
5580	@ Test 
56- 	public  void  testRefresh (EntityManagerFactoryScope  scope ) {
81+ 	public  void  testRefresh (SessionFactoryScope  scope ) {
5782		scope .inTransaction (
5883				session  -> {
5984					User  user  = session .createQuery ( "select u from User u where u.id = :id" , User .class  )
6085							.setParameter ( "id" , 1l  )
6186							.getSingleResult ();
87+ 					assertThat ( Hibernate .isInitialized ( user .getInfo () ) ).isFalse ();
6288					session .refresh ( user .getInfo () );
89+ 					assertThat ( Hibernate .isInitialized ( user .getInfo () ) ).isTrue ();
6390				}
6491		);
6592	}
0 commit comments