Skip to content

Commit da3ad53

Browse files
committed
HHH-19179 Remove commit 50c12d9 by Alexander-Dukhno
1 parent 057e574 commit da3ad53

File tree

6 files changed

+178
-167
lines changed

6 files changed

+178
-167
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/lazyload/AtomikosJtaLazyLoadingTest.java

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
*/
55
package org.hibernate.orm.test.lazyload;
66

7+
import jakarta.persistence.CascadeType;
8+
import jakarta.persistence.Entity;
9+
import jakarta.persistence.FetchType;
10+
import jakarta.persistence.GeneratedValue;
11+
import jakarta.persistence.Id;
12+
import jakarta.persistence.ManyToOne;
13+
import jakarta.persistence.OneToMany;
714
import org.hibernate.Hibernate;
815
import org.hibernate.cfg.AvailableSettings;
916
import org.hibernate.cfg.Environment;
@@ -17,6 +24,9 @@
1724
import org.junit.jupiter.api.BeforeEach;
1825
import org.junit.jupiter.api.Test;
1926

27+
import java.util.ArrayList;
28+
import java.util.List;
29+
2030
import static org.junit.jupiter.api.Assertions.assertEquals;
2131
import static org.junit.jupiter.api.Assertions.assertFalse;
2232
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -27,8 +37,8 @@
2737
*/
2838
@DomainModel(
2939
annotatedClasses = {
30-
Parent.class,
31-
Child.class
40+
AtomikosJtaLazyLoadingTest.Parent.class,
41+
AtomikosJtaLazyLoadingTest.Child.class
3242
}
3343
)
3444
@SessionFactory
@@ -63,7 +73,7 @@ public void prepareTest(SessionFactoryScope scope)
6373
scope.inTransaction( session -> {
6474
Parent p = new Parent();
6575
for ( int i = 0; i < CHILDREN_SIZE; i++ ) {
66-
final Child child = p.makeChild();
76+
final Child child = new Child(p);
6777
session.persist( child );
6878
lastChildID = child.getId();
6979
}
@@ -105,4 +115,55 @@ public void testLazyCollectionLoadingAfterEndTransaction(SessionFactoryScope sco
105115
assertEquals( CHILDREN_SIZE, j );
106116
}
107117

118+
@Entity(name = "Parent")
119+
public static class Parent {
120+
@Id
121+
@GeneratedValue
122+
private Long id;
123+
124+
private String name;
125+
126+
127+
128+
@OneToMany(cascade = CascadeType.PERSIST)
129+
private List<Child> children = new ArrayList<>();
130+
131+
public Long getId() {
132+
return id;
133+
}
134+
135+
public List<Child> getChildren() {
136+
return children;
137+
}
138+
}
139+
140+
@Entity(name = "Child")
141+
public static class Child {
142+
143+
@Id
144+
@GeneratedValue
145+
private Long id;
146+
147+
private String name;
148+
149+
@ManyToOne(fetch = FetchType.LAZY)
150+
private Parent parent;
151+
152+
public Child() {
153+
}
154+
155+
public Child(Parent parent) {
156+
this.parent = parent;
157+
parent.getChildren().add( this );
158+
}
159+
160+
public Long getId() {
161+
return id;
162+
}
163+
164+
public Parent getParent() {
165+
return parent;
166+
}
167+
}
168+
108169
}

hibernate-core/src/test/java/org/hibernate/orm/test/lazyload/Child.java

Lines changed: 0 additions & 47 deletions
This file was deleted.

hibernate-core/src/test/java/org/hibernate/orm/test/lazyload/JtaLazyLoadingTest.java

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
*/
55
package org.hibernate.orm.test.lazyload;
66

7+
import jakarta.persistence.CascadeType;
8+
import jakarta.persistence.Entity;
9+
import jakarta.persistence.FetchType;
10+
import jakarta.persistence.GeneratedValue;
11+
import jakarta.persistence.Id;
12+
import jakarta.persistence.ManyToOne;
13+
import jakarta.persistence.OneToMany;
714
import org.hibernate.Hibernate;
815
import org.hibernate.cfg.AvailableSettings;
916
import org.hibernate.cfg.Environment;
@@ -17,6 +24,9 @@
1724
import org.junit.jupiter.api.BeforeEach;
1825
import org.junit.jupiter.api.Test;
1926

27+
import java.util.ArrayList;
28+
import java.util.List;
29+
2030
import static org.junit.jupiter.api.Assertions.assertEquals;
2131
import static org.junit.jupiter.api.Assertions.assertFalse;
2232
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -27,8 +37,8 @@
2737
*/
2838
@DomainModel(
2939
annotatedClasses = {
30-
Parent.class,
31-
Child.class
40+
JtaLazyLoadingTest.Parent.class,
41+
JtaLazyLoadingTest.Child.class
3242
}
3343
)
3444
@SessionFactory
@@ -61,7 +71,7 @@ public void prepareTest(SessionFactoryScope scope)
6171
scope.inTransaction(
6272
session -> {
6373
for ( int i = 0; i < CHILDREN_SIZE; i++ ) {
64-
final Child child = p.makeChild();
74+
final Child child = new Child( p );
6575
session.persist( child );
6676
lastChildID = child.getId();
6777
}
@@ -106,4 +116,52 @@ public void testLazyCollectionLoadingAfterEndTransaction(SessionFactoryScope sco
106116
assertEquals( CHILDREN_SIZE, j );
107117
}
108118

119+
@Entity(name = "Parent")
120+
public static class Parent {
121+
@Id
122+
@GeneratedValue
123+
private Long id;
124+
125+
private String name;
126+
127+
@OneToMany(cascade = CascadeType.PERSIST)
128+
private List<Child> children = new ArrayList<>();
129+
130+
public Long getId() {
131+
return id;
132+
}
133+
134+
public List<Child> getChildren() {
135+
return children;
136+
}
137+
}
138+
139+
@Entity(name = "Child")
140+
public static class Child {
141+
142+
@Id
143+
@GeneratedValue
144+
private Long id;
145+
146+
private String name;
147+
148+
@ManyToOne(fetch = FetchType.LAZY)
149+
private Parent parent;
150+
151+
public Child(){}
152+
153+
public Child(Parent parent) {
154+
this.parent = parent;
155+
parent.getChildren().add( this );
156+
}
157+
158+
public Long getId() {
159+
return id;
160+
}
161+
162+
public Parent getParent() {
163+
return parent;
164+
}
165+
}
166+
109167
}

hibernate-core/src/test/java/org/hibernate/orm/test/lazyload/LazyLoadingNotFoundTest.java

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
*/
55
package org.hibernate.orm.test.lazyload;
66

7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.FetchType;
9+
import jakarta.persistence.GeneratedValue;
10+
import jakarta.persistence.Id;
11+
import jakarta.persistence.ManyToOne;
12+
import jakarta.persistence.OneToMany;
713
import org.hibernate.LazyInitializationException;
814
import org.hibernate.cfg.Environment;
915

@@ -15,6 +21,9 @@
1521
import org.hibernate.testing.orm.junit.Setting;
1622
import org.junit.jupiter.api.Test;
1723

24+
import java.util.ArrayList;
25+
import java.util.List;
26+
1827
import static org.junit.jupiter.api.Assertions.assertNotNull;
1928
import static org.junit.jupiter.api.Assertions.fail;
2029

@@ -24,8 +33,8 @@
2433
*/
2534
@DomainModel(
2635
annotatedClasses = {
27-
Parent.class,
28-
Child.class
36+
LazyLoadingNotFoundTest.Parent.class,
37+
LazyLoadingNotFoundTest.Child.class
2938
}
3039
)
3140
@SessionFactory
@@ -47,4 +56,46 @@ public void testNonExistentLazyInitOutsideTransaction(SessionFactoryScope scope)
4756
assertNotNull( e.getMessage() );
4857
}
4958
}
59+
60+
@Entity(name = "Parent")
61+
public static class Parent {
62+
@Id
63+
@GeneratedValue
64+
private Long id;
65+
66+
private String name;
67+
68+
@OneToMany
69+
private List<Child> children = new ArrayList<>();
70+
71+
public Long getId() {
72+
return id;
73+
}
74+
75+
public List<Child> getChildren() {
76+
return children;
77+
}
78+
}
79+
80+
@Entity(name = "Child")
81+
public static class Child {
82+
83+
@Id
84+
@GeneratedValue
85+
private Long id;
86+
87+
private String name;
88+
89+
@ManyToOne(fetch = FetchType.LAZY)
90+
private Parent parent;
91+
92+
public Long getId() {
93+
return id;
94+
}
95+
96+
public Parent getParent() {
97+
return parent;
98+
}
99+
}
100+
50101
}

0 commit comments

Comments
 (0)