10
10
import jakarta .persistence .FetchType ;
11
11
import jakarta .persistence .Id ;
12
12
import jakarta .persistence .ManyToOne ;
13
+ import jakarta .persistence .Table ;
13
14
import org .hibernate .LazyInitializationException ;
14
15
import org .hibernate .annotations .FetchProfile ;
15
16
import org .hibernate .stat .spi .StatisticsImplementor ;
33
34
settings = @ Setting ( name = GENERATE_STATISTICS , value = "true" )
34
35
)
35
36
@ DomainModel ( annotatedClasses = {
36
- EntityLoadedInTwoPhaseLoadTest .Start .class ,
37
- EntityLoadedInTwoPhaseLoadTest .Mid .class ,
38
- EntityLoadedInTwoPhaseLoadTest .Finish .class ,
39
- EntityLoadedInTwoPhaseLoadTest .Via1 .class ,
40
- EntityLoadedInTwoPhaseLoadTest .Via2 .class
37
+ EntityLoadedInTwoPhaseLoadTest .StartNode .class ,
38
+ EntityLoadedInTwoPhaseLoadTest .MiddleNode .class ,
39
+ EntityLoadedInTwoPhaseLoadTest .TerminalNode .class ,
40
+ EntityLoadedInTwoPhaseLoadTest .Branch1Node .class ,
41
+ EntityLoadedInTwoPhaseLoadTest .Branch2Node .class
41
42
} )
42
43
@ SessionFactory
43
44
public class EntityLoadedInTwoPhaseLoadTest {
@@ -48,9 +49,9 @@ public void testIfAllRelationsAreInitialized(SessionFactoryScope sessions) {
48
49
final StatisticsImplementor statistics = sessions .getSessionFactory ().getStatistics ();
49
50
statistics .clear ();
50
51
51
- final Start start = sessions .fromTransaction ( (session ) -> {
52
+ final StartNode startNode = sessions .fromTransaction ( (session ) -> {
52
53
session .enableFetchProfile ( FETCH_PROFILE_NAME );
53
- return session .find ( Start .class , 1 );
54
+ return session .find ( StartNode .class , 1 );
54
55
} );
55
56
56
57
// should have loaded all the data
@@ -60,8 +61,7 @@ public void testIfAllRelationsAreInitialized(SessionFactoryScope sessions) {
60
61
61
62
try {
62
63
// access the data which was supposed to have been fetched
63
- //noinspection ResultOfMethodCallIgnored
64
- start .getVia2 ().getMid ().getFinish ().getValue ();
64
+ assertThat ( startNode .branch2Node .middleNode .terminalNode .name ).isNotNull ();
65
65
}
66
66
catch (LazyInitializationException e ) {
67
67
fail ( "Everything should be initialized" );
@@ -71,12 +71,12 @@ public void testIfAllRelationsAreInitialized(SessionFactoryScope sessions) {
71
71
@ BeforeEach
72
72
void createTestData (SessionFactoryScope sessions ) {
73
73
sessions .inTransaction ( (session ) -> {
74
- Finish finish = new Finish ( 1 , "foo" );
75
- Mid mid = new Mid ( 1 , finish );
76
- Via2 via2 = new Via2 ( 1 , mid );
77
- Start start = new Start ( 1 , null , via2 );
74
+ TerminalNode terminalNode = new TerminalNode ( 1 , "foo" );
75
+ MiddleNode middleNode = new MiddleNode ( 1 , terminalNode );
76
+ Branch2Node branch2Node = new Branch2Node ( 1 , middleNode );
77
+ StartNode startNode = new StartNode ( 1 , null , branch2Node );
78
78
79
- session .persist ( start );
79
+ session .persist ( startNode );
80
80
} );
81
81
}
82
82
@@ -85,171 +85,107 @@ void dropTestData(SessionFactoryScope sessions) {
85
85
sessions .dropData ();
86
86
}
87
87
88
- @ Entity (name = "FinishEntity" )
89
- public static class Finish {
88
+ @ Entity
89
+ @ Table (name ="start_node" )
90
+ @ FetchProfile (name = FETCH_PROFILE_NAME , fetchOverrides = {
91
+ @ FetchProfile .FetchOverride (entity = StartNode .class , association = "branch1Node" ),
92
+ @ FetchProfile .FetchOverride (entity = StartNode .class , association = "branch2Node" )
93
+ })
94
+ @ SuppressWarnings ({"FieldCanBeLocal" , "unused" })
95
+ public static class StartNode {
90
96
@ Id
91
97
private Integer id ;
92
- @ Column (name = "val" , nullable = false )
93
- private String value ;
98
+ @ ManyToOne (fetch = FetchType .LAZY , cascade = CascadeType .PERSIST )
99
+ private Branch1Node branch1Node ;
100
+ @ ManyToOne (fetch = FetchType .LAZY , cascade = CascadeType .PERSIST )
101
+ private Branch2Node branch2Node ;
94
102
95
- public Finish () {
103
+ public StartNode () {
96
104
}
97
105
98
- public Finish (Integer id , String value ) {
106
+ public StartNode (Integer id , Branch1Node branch1Node , Branch2Node branch2Node ) {
99
107
this .id = id ;
100
- this .value = value ;
101
- }
102
-
103
- public Integer getId () {
104
- return id ;
105
- }
106
-
107
- public String getValue () {
108
- return value ;
109
- }
110
-
111
- public void setValue (String value ) {
112
- this .value = value ;
108
+ this .branch1Node = branch1Node ;
109
+ this .branch2Node = branch2Node ;
113
110
}
114
111
}
115
112
116
- @ Entity (name = "MidEntity " )
113
+ @ Entity (name = "Via1Entity " )
117
114
@ FetchProfile (name = FETCH_PROFILE_NAME , fetchOverrides = {
118
- @ FetchProfile .FetchOverride (entity = Mid .class , association = "finish " )
115
+ @ FetchProfile .FetchOverride (entity = Branch1Node .class , association = "middleNode " )
119
116
})
120
- public static class Mid {
117
+ @ SuppressWarnings ({"FieldCanBeLocal" , "unused" })
118
+ public static class Branch1Node {
121
119
@ Id
122
120
private Integer id ;
123
121
@ ManyToOne (fetch = FetchType .LAZY , cascade = CascadeType .PERSIST )
124
- private Finish finish ;
122
+ private MiddleNode middleNode ;
125
123
126
- public Mid () {
124
+ public Branch1Node () {
127
125
}
128
126
129
- public Mid (Integer id , Finish finish ) {
127
+ public Branch1Node (Integer id , MiddleNode middleNode ) {
130
128
this .id = id ;
131
- this .finish = finish ;
132
- }
133
-
134
- public Integer getId () {
135
- return id ;
129
+ this .middleNode = middleNode ;
136
130
}
137
-
138
- public Finish getFinish () {
139
- return finish ;
140
- }
141
-
142
- public void setFinish (Finish finish ) {
143
- this .finish = finish ;
144
- }
145
-
146
131
}
147
132
148
- @ Entity (name = "StartEntity " )
133
+ @ Entity (name = "Via2Entity " )
149
134
@ FetchProfile (name = FETCH_PROFILE_NAME , fetchOverrides = {
150
- @ FetchProfile .FetchOverride (entity = Start .class , association = "via1" ),
151
- @ FetchProfile .FetchOverride (entity = Start .class , association = "via2" )
135
+ @ FetchProfile .FetchOverride (entity = Branch2Node .class , association = "middleNode" )
152
136
})
153
- public static class Start {
137
+ @ SuppressWarnings ({"FieldCanBeLocal" , "unused" })
138
+ public static class Branch2Node {
154
139
@ Id
155
140
private Integer id ;
156
141
@ ManyToOne (fetch = FetchType .LAZY , cascade = CascadeType .PERSIST )
157
- private Via1 via1 ;
158
- @ ManyToOne (fetch = FetchType .LAZY , cascade = CascadeType .PERSIST )
159
- private Via2 via2 ;
142
+ private MiddleNode middleNode ;
160
143
161
- public Start () {
144
+ public Branch2Node () {
162
145
}
163
146
164
- public Start (Integer id , Via1 via1 , Via2 via2 ) {
147
+ public Branch2Node (Integer id , MiddleNode middleNode ) {
165
148
this .id = id ;
166
- this .via1 = via1 ;
167
- this .via2 = via2 ;
168
- }
169
-
170
- public Integer getId () {
171
- return id ;
172
- }
173
-
174
- public Via1 getVia1 () {
175
- return via1 ;
176
- }
177
-
178
- public void setVia1 (Via1 via1 ) {
179
- this .via1 = via1 ;
180
- }
181
-
182
- public Via2 getVia2 () {
183
- return via2 ;
149
+ this .middleNode = middleNode ;
184
150
}
185
-
186
- public void setVia2 (Via2 via2 ) {
187
- this .via2 = via2 ;
188
- }
189
-
190
151
}
191
152
192
- @ Entity (name = "Via1Entity" )
153
+ @ Entity
154
+ @ Table (name ="middle_node" )
193
155
@ FetchProfile (name = FETCH_PROFILE_NAME , fetchOverrides = {
194
- @ FetchProfile .FetchOverride (entity = Via1 .class , association = "mid " )
156
+ @ FetchProfile .FetchOverride (entity = MiddleNode .class , association = "terminalNode " )
195
157
})
196
- public static class Via1 {
158
+ @ SuppressWarnings ({"FieldCanBeLocal" , "unused" })
159
+ public static class MiddleNode {
197
160
@ Id
198
161
private Integer id ;
199
162
@ ManyToOne (fetch = FetchType .LAZY , cascade = CascadeType .PERSIST )
200
- private Mid mid ;
163
+ private TerminalNode terminalNode ;
201
164
202
- public Via1 () {
165
+ public MiddleNode () {
203
166
}
204
167
205
- public Via1 (Integer id , Mid mid ) {
168
+ public MiddleNode (Integer id , TerminalNode terminalNode ) {
206
169
this .id = id ;
207
- this .mid = mid ;
208
- }
209
-
210
- public Integer getId () {
211
- return id ;
212
- }
213
-
214
- public Mid getMid () {
215
- return mid ;
216
- }
217
-
218
- public void setMid (Mid mid ) {
219
- this .mid = mid ;
170
+ this .terminalNode = terminalNode ;
220
171
}
221
-
222
172
}
223
173
224
- @ Entity (name = "Via2Entity" )
225
- @ FetchProfile (name = FETCH_PROFILE_NAME , fetchOverrides = {
226
- @ FetchProfile .FetchOverride (entity = Via2 .class , association = "mid" )
227
- })
228
- public static class Via2 {
174
+ @ Entity
175
+ @ Table (name ="terminal_node" )
176
+ @ SuppressWarnings ({"FieldCanBeLocal" , "unused" })
177
+ public static class TerminalNode {
229
178
@ Id
230
179
private Integer id ;
231
- @ ManyToOne ( fetch = FetchType . LAZY , cascade = CascadeType . PERSIST )
232
- private Mid mid ;
180
+ @ Column ( nullable = false )
181
+ private String name ;
233
182
234
- public Via2 () {
183
+ public TerminalNode () {
235
184
}
236
185
237
- public Via2 (Integer id , Mid mid ) {
186
+ public TerminalNode (Integer id , String name ) {
238
187
this .id = id ;
239
- this .mid = mid ;
240
- }
241
-
242
- public Integer getId () {
243
- return id ;
244
- }
245
-
246
- public Mid getMid () {
247
- return mid ;
188
+ this .name = name ;
248
189
}
249
-
250
- public void setMid (Mid mid ) {
251
- this .mid = mid ;
252
- }
253
-
254
190
}
255
191
}
0 commit comments