File tree Expand file tree Collapse file tree 5 files changed +143
-0
lines changed
tooling/metamodel-generator/src
jakartaData/java/org/hibernate/processor/test/data/idclass
test/java/org/hibernate/processor/test/idclass Expand file tree Collapse file tree 5 files changed +143
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * SPDX-License-Identifier: LGPL-2.1-or-later
3
+ * Copyright Red Hat Inc. and Hibernate Authors
4
+ */
5
+ package org .hibernate .processor .test .data .idclass ;
6
+
7
+ import org .hibernate .processor .test .data .idclass .MyEntity .MyEntityId ;
8
+ import org .hibernate .processor .test .util .CompilationTest ;
9
+ import org .hibernate .processor .test .util .WithClasses ;
10
+ import org .junit .Test ;
11
+
12
+ import static org .hibernate .processor .test .util .TestUtil .assertMetamodelClassGeneratedFor ;
13
+ import static org .hibernate .processor .test .util .TestUtil .assertPresenceOfMethodInMetamodelFor ;
14
+ import static org .hibernate .processor .test .util .TestUtil .getMetaModelSourceAsString ;
15
+
16
+ public class CompositeIdClassTest extends CompilationTest {
17
+ @ Test
18
+ @ WithClasses ({
19
+ MyRepository .class ,
20
+ MyEntity .class ,
21
+ })
22
+ public void test () {
23
+ System .out .println ( getMetaModelSourceAsString ( MyEntity .class ) );
24
+ System .out .println ( getMetaModelSourceAsString ( MyEntity .class , true ) );
25
+ System .out .println ( getMetaModelSourceAsString ( MyRepository .class ) );
26
+ assertMetamodelClassGeneratedFor ( MyEntity .class );
27
+ assertMetamodelClassGeneratedFor ( MyEntity .class , true );
28
+ assertMetamodelClassGeneratedFor ( MyRepository .class );
29
+ assertPresenceOfMethodInMetamodelFor (
30
+ MyRepository .class ,
31
+ "findById" ,
32
+ MyEntityId .class
33
+ );
34
+ }
35
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * SPDX-License-Identifier: LGPL-2.1-or-later
3
+ * Copyright Red Hat Inc. and Hibernate Authors
4
+ */
5
+ package org .hibernate .processor .test .data .idclass ;
6
+
7
+ import jakarta .persistence .Entity ;
8
+ import jakarta .persistence .Id ;
9
+ import jakarta .persistence .IdClass ;
10
+
11
+ @ Entity
12
+ @ IdClass (MyEntity .MyEntityId .class )
13
+ public class MyEntity {
14
+
15
+ @ Id
16
+ Integer topicId ;
17
+
18
+ @ Id
19
+ String userId ;
20
+
21
+ String status ;
22
+
23
+ public record MyEntityId (Integer topicId , String userId ) {
24
+
25
+ }
26
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * SPDX-License-Identifier: LGPL-2.1-or-later
3
+ * Copyright Red Hat Inc. and Hibernate Authors
4
+ */
5
+ package org .hibernate .processor .test .data .idclass ;
6
+
7
+ import jakarta .data .repository .Query ;
8
+ import jakarta .data .repository .Repository ;
9
+ import org .hibernate .processor .test .data .idclass .MyEntity .MyEntityId ;
10
+
11
+ @ Repository
12
+ public interface MyRepository {
13
+
14
+ @ Query ("from MyEntity where id=:id" )
15
+ MyEntity findById (MyEntityId id );
16
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * SPDX-License-Identifier: LGPL-2.1-or-later
3
+ * Copyright Red Hat Inc. and Hibernate Authors
4
+ */
5
+ package org .hibernate .processor .test .idclass ;
6
+
7
+ import jakarta .persistence .EntityManager ;
8
+ import org .hibernate .processor .test .idclass .MyEntity .MyEntityId ;
9
+ import org .hibernate .processor .test .util .CompilationTest ;
10
+ import org .hibernate .processor .test .util .WithClasses ;
11
+ import org .junit .Test ;
12
+
13
+ import static org .hibernate .processor .test .util .TestUtil .assertMetamodelClassGeneratedFor ;
14
+ import static org .hibernate .processor .test .util .TestUtil .assertPresenceOfMethodInMetamodelFor ;
15
+ import static org .hibernate .processor .test .util .TestUtil .assertPresenceOfNameFieldInMetamodelFor ;
16
+ import static org .hibernate .processor .test .util .TestUtil .getMetaModelSourceAsString ;
17
+
18
+ public class CompositeIdClassTest extends CompilationTest {
19
+ @ Test
20
+ @ WithClasses (MyEntity .class )
21
+ public void test () {
22
+ System .out .println ( getMetaModelSourceAsString ( MyEntity .class ) );
23
+ assertMetamodelClassGeneratedFor ( MyEntity .class );
24
+ assertPresenceOfNameFieldInMetamodelFor (
25
+ MyEntity .class ,
26
+ "QUERY_FIND_BY_ID" ,
27
+ "Missing named query attribute."
28
+ );
29
+ assertPresenceOfMethodInMetamodelFor (
30
+ MyEntity .class ,
31
+ "findById" ,
32
+ EntityManager .class ,
33
+ MyEntityId .class
34
+ );
35
+ }
36
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * SPDX-License-Identifier: LGPL-2.1-or-later
3
+ * Copyright Red Hat Inc. and Hibernate Authors
4
+ */
5
+ package org .hibernate .processor .test .idclass ;
6
+
7
+ import jakarta .persistence .Entity ;
8
+ import jakarta .persistence .Id ;
9
+ import jakarta .persistence .IdClass ;
10
+ import jakarta .persistence .NamedQuery ;
11
+ import org .hibernate .annotations .processing .CheckHQL ;
12
+
13
+ @ Entity
14
+ @ IdClass (MyEntity .MyEntityId .class )
15
+ @ CheckHQL
16
+ @ NamedQuery (name = "#findById" , query = "from MyEntity e where e.id=:id" )
17
+ public class MyEntity {
18
+
19
+ @ Id
20
+ Integer topicId ;
21
+
22
+ @ Id
23
+ String userId ;
24
+
25
+ String status ;
26
+
27
+ public record MyEntityId (Integer topicId , String userId ) {
28
+
29
+ }
30
+ }
You can’t perform that action at this time.
0 commit comments