|
5 | 5 | package org.hibernate.processor.test.namedquery;
|
6 | 6 |
|
7 | 7 | import jakarta.persistence.EntityManager;
|
| 8 | +import jakarta.persistence.TypedQueryReference; |
8 | 9 | import org.hibernate.processor.test.util.CompilationTest;
|
9 | 10 | import org.hibernate.processor.test.util.TestUtil;
|
10 | 11 | import org.hibernate.processor.test.util.WithClasses;
|
11 | 12 | import org.junit.Test;
|
12 | 13 |
|
| 14 | +import java.lang.reflect.ParameterizedType; |
| 15 | + |
13 | 16 | import static org.hibernate.processor.test.util.TestUtil.assertMetamodelClassGeneratedFor;
|
| 17 | +import static org.hibernate.processor.test.util.TestUtil.assertPresenceOfFieldInMetamodelFor; |
14 | 18 | import static org.hibernate.processor.test.util.TestUtil.assertPresenceOfMethodInMetamodelFor;
|
15 | 19 | import static org.hibernate.processor.test.util.TestUtil.assertPresenceOfNameFieldInMetamodelFor;
|
| 20 | +import static org.hibernate.processor.test.util.TestUtil.getFieldFromMetamodelFor; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
16 | 22 |
|
17 | 23 | /**
|
18 | 24 | * @author Gavin King
|
@@ -129,5 +135,31 @@ public void test() {
|
129 | 135 | Object.class,
|
130 | 136 | Object.class
|
131 | 137 | );
|
| 138 | + |
| 139 | + checkTypedQueryReference( "QUERY_TITLES_WITH_ISBNS", "_titlesWithIsbns_", Object[].class ); |
| 140 | + checkTypedQueryReference( "QUERY_TITLES_AND_ISBNS_AS_RECORD", "_titlesAndIsbnsAsRecord_", TitleAndIsbn.class ); |
| 141 | + checkTypedQueryReference( "QUERY_TYPE_OF_BOOK", "__typeOfBook_", Type.class ); |
| 142 | + checkTypedQueryReference( "QUERY_GET_TITLES", "__getTitles_", String.class ); |
| 143 | + checkTypedQueryReference( "QUERY_GET_UPPER_LOWER_TITLES", "__getUpperLowerTitles_", Object[].class ); |
| 144 | + checkTypedQueryReference( "QUERY_BOOKS_BY_TITLE", "_booksByTitle_", Book.class ); |
| 145 | + checkTypedQueryReference( "QUERY_BOOKS_BY_TITLE_VERBOSE", "_booksByTitleVerbose_", Book.class ); |
| 146 | + } |
| 147 | + |
| 148 | + private static void checkTypedQueryReference(String NAME, String name, Class<?> type) { |
| 149 | + assertPresenceOfNameFieldInMetamodelFor( |
| 150 | + Book.class, |
| 151 | + NAME, |
| 152 | + "Missing named query attribute." |
| 153 | + ); |
| 154 | + assertPresenceOfFieldInMetamodelFor( |
| 155 | + Book.class, |
| 156 | + name, |
| 157 | + "Missing typed query reference." |
| 158 | + ); |
| 159 | + ParameterizedType fieldType = (ParameterizedType) |
| 160 | + getFieldFromMetamodelFor( Book.class, name ) |
| 161 | + .getGenericType(); |
| 162 | + assertEquals(TypedQueryReference.class, fieldType.getRawType()); |
| 163 | + assertEquals( type, fieldType.getActualTypeArguments()[0]); |
132 | 164 | }
|
133 | 165 | }
|
0 commit comments