HHH-18358 Test case - create metamodel from entity class containing named query comparing type(.) with literal

This commit is contained in:
Čedomir Igaly 2024-07-09 10:13:19 +02:00 committed by Gavin King
parent 93b2fc2bbd
commit e71f874e1f
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,37 @@
package org.hibernate.processor.test.typeliteral;
import org.hibernate.processor.test.util.CompilationTest;
import org.hibernate.processor.test.util.TestForIssue;
import org.hibernate.processor.test.util.TestUtil;
import org.hibernate.processor.test.util.WithClasses;
import org.junit.Test;
import jakarta.persistence.EntityManager;
import static org.hibernate.processor.test.util.TestUtil.assertMetamodelClassGeneratedFor;
import static org.hibernate.processor.test.util.TestUtil.assertPresenceOfFieldInMetamodelFor;
import static org.hibernate.processor.test.util.TestUtil.assertPresenceOfMethodInMetamodelFor;
public class TypeLiteralTest extends CompilationTest {
@Test
@WithClasses(
value = {},
sources = "org.hibernate.processor.test.typeliteral.Simple"
)
@TestForIssue(jiraKey = "HHH-18358")
public void namedQueryWithTypeLiteral() {
final String entityClass = "org.hibernate.processor.test.typeliteral.Simple";
System.out.println( TestUtil.getMetaModelSourceAsString( entityClass ) );
assertMetamodelClassGeneratedFor( entityClass );
assertPresenceOfFieldInMetamodelFor( entityClass, "QUERY_SIMPLE" );
assertPresenceOfFieldInMetamodelFor( entityClass, "QUERY_LONGER" );
assertPresenceOfMethodInMetamodelFor( entityClass, "simple", EntityManager.class );
assertPresenceOfMethodInMetamodelFor( entityClass, "longer", EntityManager.class );
}
}

View File

@ -0,0 +1,17 @@
package org.hibernate.processor.test.typeliteral;
import org.hibernate.annotations.NamedQuery;
import org.hibernate.annotations.processing.CheckHQL;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
@Entity
@CheckHQL
@NamedQuery(name = "#simple", query = "select s from Simple s where type(s) = Simple")
@NamedQuery(name = "#longer", query = "select s from Simple s where type(s) = org.hibernate.processor.test.typeliteral.Simple")
public class Simple {
@Id
private Integer id;
private String value;
}