23
23
import jakarta .persistence .Table ;
24
24
25
25
26
+
26
27
public class LazyOneToOneWithJoinColumnTest extends BaseReactiveTest {
27
28
28
29
@ Override
@@ -34,41 +35,41 @@ protected Collection<Class<?>> annotatedEntities() {
34
35
public void testLoad (TestContext context ) {
35
36
final Endpoint endpoint = new Endpoint ();
36
37
final EndpointWebhook webhook = new EndpointWebhook ();
37
- endpoint .webhook = webhook ;
38
- webhook .endpoint = endpoint ;
38
+ endpoint .setWebhook ( webhook ) ;
39
+ webhook .setEndpoint ( endpoint ) ;
39
40
40
41
test ( context , openMutinySession ()
41
42
.chain ( session -> session
42
43
.persist ( endpoint )
43
44
.chain ( session ::flush ) )
44
45
.chain ( this ::openMutinySession )
45
46
.chain ( session -> session
46
- .find ( Endpoint .class , endpoint .id )
47
+ .find ( Endpoint .class , endpoint .getId () )
47
48
.invoke ( optionalAnEntity -> {
48
49
context .assertNotNull ( optionalAnEntity );
49
- context .assertNotNull ( optionalAnEntity .webhook );
50
+ context .assertNotNull ( optionalAnEntity .getWebhook () );
50
51
// This is eager because the other table contains the reference
51
- context .assertTrue ( Hibernate .isInitialized ( optionalAnEntity .webhook ) );
52
+ context .assertTrue ( Hibernate .isInitialized ( optionalAnEntity .getWebhook () ) );
52
53
} ) )
53
54
.chain ( this ::openMutinySession )
54
55
.chain ( session -> session
55
- .find ( EndpointWebhook .class , webhook .id )
56
+ .find ( EndpointWebhook .class , webhook .getId () )
56
57
.invoke ( optionalAnEntity -> {
57
58
context .assertNotNull ( optionalAnEntity );
58
- context .assertNotNull ( optionalAnEntity .endpoint );
59
- // This i actually lazy
60
- context .assertFalse ( Hibernate .isInitialized ( optionalAnEntity .endpoint ) );
59
+ context .assertNotNull ( optionalAnEntity .getEndpoint () );
60
+ // This is actually lazy
61
+ context .assertFalse ( Hibernate .isInitialized ( optionalAnEntity .getEndpoint () ) );
61
62
} ) )
62
63
);
63
64
}
64
65
65
66
@ Test
66
67
public void testQuery (TestContext context ) {
67
68
final Endpoint endpoint = new Endpoint ();
68
- endpoint .accountId = "XYZ_123" ;
69
+ endpoint .setAccountId ( "XYZ_123" ) ;
69
70
final EndpointWebhook webhook = new EndpointWebhook ();
70
- endpoint .webhook = webhook ;
71
- webhook .endpoint = endpoint ;
71
+ endpoint .setWebhook ( webhook ) ;
72
+ webhook .setEndpoint ( endpoint ) ;
72
73
73
74
String query = "FROM Endpoint WHERE id = :id AND accountId = :accountId" ;
74
75
test ( context , openMutinySession ()
@@ -78,14 +79,14 @@ public void testQuery(TestContext context) {
78
79
.chain ( this ::openMutinySession )
79
80
.chain ( session -> session
80
81
.createQuery ( query , Endpoint .class )
81
- .setParameter ( "id" , endpoint .id )
82
- .setParameter ( "accountId" , endpoint .accountId )
82
+ .setParameter ( "id" , endpoint .getId () )
83
+ .setParameter ( "accountId" , endpoint .getAccountId () )
83
84
.getSingleResultOrNull ()
84
85
.invoke ( result -> {
85
86
context .assertNotNull ( result );
86
- context .assertTrue ( Hibernate .isInitialized ( result .webhook ) );
87
- context .assertEquals ( endpoint .id , result .id );
88
- context .assertEquals ( webhook .id , result .webhook . id );
87
+ context .assertTrue ( Hibernate .isInitialized ( result .getWebhook () ) );
88
+ context .assertEquals ( endpoint .getId () , result .getId () );
89
+ context .assertEquals ( webhook .getId () , result .getWebhook (). getId () );
89
90
} ) )
90
91
);
91
92
}
@@ -96,13 +97,36 @@ public static class Endpoint {
96
97
97
98
@ Id
98
99
@ GeneratedValue
99
- public Long id ;
100
+ private Long id ;
100
101
101
102
@ OneToOne (mappedBy = "endpoint" , fetch = FetchType .LAZY , cascade = CascadeType .ALL )
102
- public EndpointWebhook webhook ;
103
+ private EndpointWebhook webhook ;
104
+
105
+ private String accountId ;
106
+
107
+ public Long getId () {
108
+ return id ;
109
+ }
110
+
111
+ public void setId (Long id ) {
112
+ this .id = id ;
113
+ }
114
+
115
+ public EndpointWebhook getWebhook () {
116
+ return webhook ;
117
+ }
118
+
119
+ public void setWebhook (EndpointWebhook webhook ) {
120
+ this .webhook = webhook ;
121
+ }
103
122
104
- public String accountId ;
123
+ public String getAccountId () {
124
+ return accountId ;
125
+ }
105
126
127
+ public void setAccountId (String accountId ) {
128
+ this .accountId = accountId ;
129
+ }
106
130
107
131
@ Override
108
132
public String toString () {
@@ -121,11 +145,27 @@ public static class EndpointWebhook {
121
145
122
146
@ Id
123
147
@ GeneratedValue
124
- public Long id ;
148
+ private Long id ;
125
149
126
150
@ OneToOne (fetch = FetchType .LAZY )
127
151
@ JoinColumn (name = "endpoint_id" )
128
- public Endpoint endpoint ;
152
+ private Endpoint endpoint ;
153
+
154
+ public Long getId () {
155
+ return id ;
156
+ }
157
+
158
+ public void setId (Long id ) {
159
+ this .id = id ;
160
+ }
161
+
162
+ public Endpoint getEndpoint () {
163
+ return endpoint ;
164
+ }
165
+
166
+ public void setEndpoint (Endpoint endpoint ) {
167
+ this .endpoint = endpoint ;
168
+ }
129
169
130
170
@ Override
131
171
public String toString () {
0 commit comments