4
4
*/
5
5
package org .hibernate .orm .test .querycache ;
6
6
7
- import java .util .Arrays ;
8
- import java .util .List ;
9
- import java .util .Set ;
10
-
11
- import org .hibernate .annotations .JdbcTypeCode ;
12
- import org .hibernate .type .SqlTypes ;
13
-
14
- import org .hibernate .testing .orm .junit .DomainModel ;
15
- import org .hibernate .testing .orm .junit .Jira ;
16
- import org .hibernate .testing .orm .junit .SessionFactory ;
17
- import org .hibernate .testing .orm .junit .SessionFactoryScope ;
18
- import org .junit .jupiter .api .AfterAll ;
19
- import org .junit .jupiter .api .BeforeAll ;
20
- import org .junit .jupiter .api .Test ;
21
-
22
- import jakarta .persistence .Access ;
23
7
import jakarta .persistence .Column ;
24
8
import jakarta .persistence .DiscriminatorColumn ;
25
9
import jakarta .persistence .DiscriminatorValue ;
28
12
import jakarta .persistence .FetchType ;
29
13
import jakarta .persistence .GeneratedValue ;
30
14
import jakarta .persistence .Id ;
15
+ import jakarta .persistence .Inheritance ;
16
+ import jakarta .persistence .InheritanceType ;
31
17
import jakarta .persistence .JoinColumn ;
32
18
import jakarta .persistence .JoinTable ;
33
19
import jakarta .persistence .ManyToMany ;
20
+ import org .hibernate .annotations .JdbcTypeCode ;
21
+ import org .hibernate .testing .orm .junit .DomainModel ;
22
+ import org .hibernate .testing .orm .junit .Jira ;
23
+ import org .hibernate .testing .orm .junit .SessionFactory ;
24
+ import org .hibernate .testing .orm .junit .SessionFactoryScope ;
25
+ import org .hibernate .type .SqlTypes ;
26
+ import org .junit .jupiter .api .AfterAll ;
27
+ import org .junit .jupiter .api .BeforeAll ;
28
+ import org .junit .jupiter .api .Test ;
29
+
30
+ import java .util .Arrays ;
31
+ import java .util .List ;
32
+ import java .util .Set ;
34
33
35
- import static jakarta .persistence .AccessType .FIELD ;
36
34
import static jakarta .persistence .EnumType .STRING ;
37
35
import static org .assertj .core .api .Assertions .assertThat ;
38
36
39
37
/**
40
- * @author miroslav silhavy
38
+ * @author Miroslav Silhavy
41
39
*/
42
40
@ DomainModel (annotatedClasses = {
43
41
EntityWithCollectionReloadCacheInheritanceTest .HighSchoolStudent .class ,
44
- EntityWithCollectionReloadCacheInheritanceTest .DefaultSubject .class ,
42
+ EntityWithCollectionReloadCacheInheritanceTest .Subject .class ,
45
43
EntityWithCollectionReloadCacheInheritanceTest .EnglishSubject .class
46
44
})
47
45
@ SessionFactory
@@ -51,7 +49,7 @@ public class EntityWithCollectionReloadCacheInheritanceTest {
51
49
@ Test
52
50
public void test (SessionFactoryScope scope ) {
53
51
scope .inTransaction ( session -> {
54
- List <HighSchoolStudent > list = session .createQuery (
52
+ List <HighSchoolStudent > highSchoolStudents = session .createQuery (
55
53
"select s" +
56
54
" from HighSchoolStudent s left join fetch s.subjects m" +
57
55
" where s.name in :names" , HighSchoolStudent .class
@@ -60,9 +58,9 @@ public void test(SessionFactoryScope scope) {
60
58
.setCacheable ( true )
61
59
.list ();
62
60
63
- assertThat ( list ).hasSize ( 1 );
61
+ assertThat ( highSchoolStudents ).hasSize ( 1 );
64
62
65
- list = session .createQuery (
63
+ highSchoolStudents = session .createQuery (
66
64
"select s" +
67
65
" from HighSchoolStudent s left join fetch s.subjects m" +
68
66
" where s.name in :names" , HighSchoolStudent .class
@@ -71,7 +69,7 @@ public void test(SessionFactoryScope scope) {
71
69
.setCacheable ( true )
72
70
.list ();
73
71
74
- assertThat ( list ).hasSize ( 2 );
72
+ assertThat ( highSchoolStudents ).hasSize ( 2 );
75
73
} );
76
74
}
77
75
@@ -94,7 +92,6 @@ public void tearDown(SessionFactoryScope scope) {
94
92
}
95
93
96
94
@ Entity (name = "HighSchoolStudent" )
97
- @ Access (FIELD )
98
95
static class HighSchoolStudent {
99
96
100
97
@ Id
@@ -105,12 +102,12 @@ static class HighSchoolStudent {
105
102
@ Column (name = "name" )
106
103
private String name ;
107
104
108
- @ ManyToMany (targetEntity = DefaultSubject .class , fetch = FetchType .LAZY )
105
+ @ ManyToMany (targetEntity = Subject .class , fetch = FetchType .LAZY )
109
106
@ JoinTable (name = "STUDENT_SUBJECT" ,
110
107
joinColumns = { @ JoinColumn (name = "student_id" ) },
111
108
inverseJoinColumns = { @ JoinColumn (name = "subject_id" ) }
112
109
)
113
- private Set <DefaultSubject > subjects ;
110
+ private Set <Subject > subjects ;
114
111
115
112
public Long getId () {
116
113
return id ;
@@ -128,37 +125,32 @@ public void setName(String name) {
128
125
this .name = name ;
129
126
}
130
127
131
- public Set <DefaultSubject > getSubjects () {
128
+ public Set <Subject > getSubjects () {
132
129
return subjects ;
133
130
}
134
131
135
- public void setMajors (Set <DefaultSubject > subjects ) {
132
+ public void setSubjects (Set <Subject > subjects ) {
136
133
this .subjects = subjects ;
137
134
}
138
135
139
136
}
140
137
141
- @ Entity (name = "DefaultSubject" )
138
+ @ Entity (name = "Subject" )
139
+ @ Inheritance (strategy = InheritanceType .SINGLE_TABLE )
142
140
@ DiscriminatorValue ("DEFAULT" )
143
141
@ DiscriminatorColumn (name = "TYPE" , length = 20 )
144
- @ Access (FIELD )
145
- static class DefaultSubject {
142
+ static class Subject {
146
143
147
- enum SubjectType {
148
- DEFAULT ,
149
- ENGLISH
150
- }
144
+ @ Id
145
+ @ GeneratedValue
146
+ @ Column ( name = "id" )
147
+ private Long id ;
151
148
152
149
@ Column (name = "TYPE" , nullable = false , length = 20 , insertable = false , updatable = false )
153
150
@ Enumerated (STRING )
154
151
@ JdbcTypeCode (SqlTypes .VARCHAR )
155
152
private SubjectType type ;
156
153
157
- @ Id
158
- @ GeneratedValue
159
- @ Column (name = "id" )
160
- private Long id ;
161
-
162
154
public Long getId () {
163
155
return id ;
164
156
}
@@ -171,8 +163,12 @@ public void setId(Long id) {
171
163
172
164
@ Entity (name = "EnglishSubject" )
173
165
@ DiscriminatorValue ("ENGLISH" )
174
- @ Access (FIELD )
175
- static class EnglishSubject extends DefaultSubject {
166
+ static class EnglishSubject extends Subject {
167
+ }
168
+
169
+ enum SubjectType {
170
+ DEFAULT ,
171
+ ENGLISH
176
172
}
177
173
178
174
}
0 commit comments