7
7
package org .hibernate .orm .test .mapping ;
8
8
9
9
import java .io .Serializable ;
10
+ import java .util .List ;
10
11
import java .util .Objects ;
12
+
13
+ import org .hibernate .testing .orm .junit .DomainModel ;
14
+ import org .hibernate .testing .orm .junit .Jira ;
15
+ import org .hibernate .testing .orm .junit .SessionFactory ;
16
+ import org .hibernate .testing .orm .junit .SessionFactoryScope ;
17
+ import org .junit .jupiter .api .AfterAll ;
18
+ import org .junit .jupiter .api .BeforeAll ;
19
+ import org .junit .jupiter .api .Test ;
20
+
21
+ import jakarta .persistence .Column ;
11
22
import jakarta .persistence .Entity ;
12
23
import jakarta .persistence .Id ;
13
24
import jakarta .persistence .IdClass ;
14
25
import jakarta .persistence .MappedSuperclass ;
26
+ import jakarta .persistence .criteria .CriteriaBuilder ;
27
+ import jakarta .persistence .criteria .CriteriaQuery ;
28
+ import jakarta .persistence .criteria .Path ;
29
+ import jakarta .persistence .criteria .Root ;
15
30
16
- import org .hibernate .testing .TestForIssue ;
17
- import org .hibernate .testing .orm .junit .DomainModel ;
18
- import org .hibernate .testing .orm .junit .SessionFactory ;
19
- import org .junit .jupiter .api .Test ;
31
+ import static org .assertj .core .api .Assertions .assertThat ;
20
32
21
- @ TestForIssue (jiraKey = "HHH-14499" )
22
33
@ DomainModel (
23
34
annotatedClasses = {
24
35
MappedSuperclassWithGenericsTest .IntermediateAbstractMapped .class ,
25
36
MappedSuperclassWithGenericsTest .BaseEntity .class ,
26
37
MappedSuperclassWithGenericsTest .AbstractGenericMappedSuperType .class ,
38
+ MappedSuperclassWithGenericsTest .SimpleEntity .class ,
39
+ MappedSuperclassWithGenericsTest .GenericIdBaseEntity .class
27
40
}
28
41
)
29
42
@ SessionFactory
30
43
public class MappedSuperclassWithGenericsTest {
31
-
32
44
@ Test
45
+ @ Jira ( "https://hibernate.atlassian.net/browse/HHH-14499" )
33
46
public void testIt () {
34
47
35
48
}
36
49
50
+ @ Test
51
+ @ Jira ( "https://hibernate.atlassian.net/browse/HHH-18007" )
52
+ void testSelectCriteriaGenericId (SessionFactoryScope scope ) {
53
+ scope .inTransaction ( session -> {
54
+ final CriteriaBuilder criteriaBuilder = session .getCriteriaBuilder ();
55
+ final CriteriaQuery <Long > criteriaQuery = criteriaBuilder .createQuery ( Long .class );
56
+ final Root <SimpleEntity > root = criteriaQuery .from ( SimpleEntity .class );
57
+ final Path <Long > idPath = root .get ( "id" );
58
+ criteriaQuery .select ( idPath );
59
+ final List <Long > resultList = session .createQuery ( criteriaQuery ).getResultList ();
60
+ assertThat ( resultList ).hasSize ( 1 ).containsOnly ( 1L );
61
+ } );
62
+ }
63
+
64
+ @ Test
65
+ @ Jira ( "https://hibernate.atlassian.net/browse/HHH-18007" )
66
+ void testSelectGenericId (SessionFactoryScope scope ) {
67
+ scope .inTransaction ( session -> {
68
+ final List <Long > resultList = session .createQuery (
69
+ "select e.id from SimpleEntity e" ,
70
+ Long .class
71
+ ).getResultList ();
72
+ assertThat ( resultList ).hasSize ( 1 ).containsOnly ( 1L );
73
+ } );
74
+ }
75
+
76
+ @ BeforeAll
77
+ public void setUp (SessionFactoryScope scope ) {
78
+ scope .inTransaction ( session -> session .persist ( new SimpleEntity ( 1L , "simple_1" ) ) );
79
+ }
80
+
81
+ @ AfterAll
82
+ public void tearDown (SessionFactoryScope scope ) {
83
+ scope .inTransaction ( session -> session .createMutationQuery ( "delete from SimpleEntity" ).executeUpdate () );
84
+ }
85
+
37
86
@ MappedSuperclass
38
87
public static abstract class AbstractGenericMappedSuperType <T > {
39
-
40
88
private T whateverType ;
41
-
42
89
}
43
90
44
91
@ MappedSuperclass
45
- @ IdClass (PK .class )
92
+ @ IdClass ( PK .class )
46
93
public static abstract class IntermediateAbstractMapped <T > extends AbstractGenericMappedSuperType <T > {
47
-
48
94
@ Id
49
95
private String keyOne ;
50
96
@ Id
@@ -53,9 +99,8 @@ public static abstract class IntermediateAbstractMapped<T> extends AbstractGener
53
99
private String keyThree ;
54
100
}
55
101
56
- @ SuppressWarnings ("UnusedDeclaration" )
102
+ @ SuppressWarnings ( "UnusedDeclaration" )
57
103
public static class PK implements Serializable {
58
-
59
104
private String keyOne ;
60
105
private String keyTwo ;
61
106
private String keyThree ;
@@ -80,11 +125,37 @@ public int hashCode() {
80
125
}
81
126
}
82
127
83
- @ Entity (name = "BaseEntity" )
128
+ @ Entity ( name = "BaseEntity" )
84
129
public static class BaseEntity <T > extends IntermediateAbstractMapped <byte []> {
85
-
86
130
String aString ;
131
+ }
132
+
133
+ @ MappedSuperclass
134
+ public static class GenericIdBaseEntity <T extends Serializable > {
135
+ @ Id
136
+ private T id ;
137
+
138
+ protected GenericIdBaseEntity (T id ) {
139
+ this .id = id ;
140
+ }
87
141
142
+ public T getId () {
143
+ return id ;
144
+ }
88
145
}
89
146
147
+ @ Entity ( name = "SimpleEntity" )
148
+ public static class SimpleEntity extends GenericIdBaseEntity <Long > {
149
+ @ Column
150
+ private String string ;
151
+
152
+ public SimpleEntity () {
153
+ super ( null );
154
+ }
155
+
156
+ protected SimpleEntity (Long id , String string ) {
157
+ super ( id );
158
+ this .string = string ;
159
+ }
160
+ }
90
161
}
0 commit comments