4
4
*/
5
5
package org .hibernate .orm .test .mapping .hhh18829 ;
6
6
7
+ import jakarta .persistence .Entity ;
8
+ import jakarta .persistence .Id ;
7
9
import org .hibernate .testing .orm .junit .DomainModel ;
8
10
import org .hibernate .testing .orm .junit .JiraKey ;
9
11
import org .hibernate .testing .orm .junit .SessionFactory ;
15
17
16
18
import static org .junit .jupiter .api .Assertions .assertEquals ;
17
19
18
- @ DomainModel (annotatedClasses = EmployeeWithoutIdClass .class )
20
+ @ DomainModel (annotatedClasses = { EmployeeWithoutIdClass .class , AutoGeneratedIdClassTest . Inner . class } )
19
21
@ JiraKey (" HHH-18829" )
20
22
@ SessionFactory
21
23
public class AutoGeneratedIdClassTest {
@@ -35,18 +37,51 @@ void setUp(SessionFactoryScope sessionFactoryScope) {
35
37
two .address = "1600 Pennsylvania Avenue" ;
36
38
sess .persist ( two );
37
39
} );
40
+ sessionFactoryScope .inTransaction ( sess -> {
41
+ final var one = new Inner ();
42
+ one .empName = "John Doe" ;
43
+ one .empId = 1 ;
44
+ one .address = "10 Downing Street, SW1A 2AA" ;
45
+ sess .persist ( one );
46
+
47
+ final var two = new Inner ();
48
+ two .empName = "Dave Default" ;
49
+ two .empId = 13 ;
50
+ two .address = "1600 Pennsylvania Avenue" ;
51
+ sess .persist ( two );
52
+ } );
38
53
}
39
54
40
55
@ Test
41
56
public void test (SessionFactoryScope sessionFactoryScope )
42
57
throws ClassNotFoundException , InvocationTargetException , InstantiationException , IllegalAccessException {
43
58
final var idClass = Class .forName ( EmployeeWithoutIdClass .class .getName () + "_$Id" );
44
- final var id = idClass .getConstructors ()[0 ].newInstance ( "John Doe" , 1 );
59
+ final var id = idClass .getConstructors ()[0 ].newInstance ( 1 , "John Doe" );
45
60
final var employees = sessionFactoryScope .fromSession (
46
- sess -> sess .createQuery ( "from EmployeeWithoutIdClass where id=:id" , EmployeeWithoutIdClass .class ).setParameter ( "id" , id )
61
+ sess -> sess .createQuery ( "from EmployeeWithoutIdClass where id=:id" , EmployeeWithoutIdClass .class )
62
+ .setParameter ( "id" , id )
47
63
.getResultList ()
48
64
);
49
65
assertEquals ( 1 , employees .size () );
50
66
assertEquals ( "10 Downing Street, SW1A 2AA" , employees .get ( 0 ).address );
51
67
}
68
+
69
+ @ Test
70
+ public void innerEntityClassTest (SessionFactoryScope sessionFactoryScope )
71
+ throws ClassNotFoundException , InvocationTargetException , InstantiationException , IllegalAccessException {
72
+ final var idClass = Class .forName ( AutoGeneratedIdClassTest .class .getName () + "_$Inner_$Id" );
73
+ final var id = idClass .getConstructors ()[0 ].newInstance ( 13 , "Dave Default" );
74
+ final Inner employee = sessionFactoryScope .fromSession (
75
+ sess -> sess .find ( Inner .class , id ) );
76
+ assertEquals ( "1600 Pennsylvania Avenue" , employee .address );
77
+ }
78
+
79
+ @ Entity
80
+ static class Inner {
81
+ @ Id
82
+ String empName ;
83
+ @ Id
84
+ Integer empId ;
85
+ String address ;
86
+ }
52
87
}
0 commit comments