HHH-18358 Bad test case replaced with one based on example from User Guide

This commit is contained in:
Čedomir Igaly 2024-07-13 11:37:28 +02:00 committed by Gavin King
parent f99bdd4b8d
commit 7862b0700a
5 changed files with 61 additions and 30 deletions

View File

@ -2,7 +2,6 @@ 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;
@ -12,26 +11,28 @@ 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;
import static org.hibernate.processor.test.util.TestUtil.getMetaModelSourceAsString;
public class TypeLiteralTest extends CompilationTest {
@Test
@WithClasses(
value = {},
sources = "org.hibernate.processor.test.typeliteral.Simple"
)
@WithClasses(value = {},
sources = {
"org.hibernate.processor.test.typeliteral.Account",
"org.hibernate.processor.test.typeliteral.CreditAccount",
"org.hibernate.processor.test.typeliteral.DebitAccount"
})
@TestForIssue(jiraKey = "HHH-18358")
public void namedQueryWithTypeLiteral() {
final String entityClass = "org.hibernate.processor.test.typeliteral.Simple";
System.out.println( TestUtil.getMetaModelSourceAsString( entityClass ) );
public void inheritance() {
final var entityClass = "org.hibernate.processor.test.typeliteral.Account";
System.out.println( getMetaModelSourceAsString( entityClass ) );
assertMetamodelClassGeneratedFor( entityClass );
assertPresenceOfFieldInMetamodelFor( entityClass, "QUERY_SIMPLE" );
assertPresenceOfFieldInMetamodelFor( entityClass, "QUERY_LONGER" );
assertPresenceOfFieldInMetamodelFor( entityClass, "QUERY_DEBIT_ACCOUNTS" );
assertPresenceOfFieldInMetamodelFor( entityClass, "QUERY_CREDIT_ACCOUNTS" );
assertPresenceOfMethodInMetamodelFor( entityClass, "simple", EntityManager.class );
assertPresenceOfMethodInMetamodelFor( entityClass, "longer", EntityManager.class );
assertPresenceOfMethodInMetamodelFor( entityClass, "debitAccounts", EntityManager.class );
assertPresenceOfMethodInMetamodelFor( entityClass, "creditAccounts", EntityManager.class );
}
}

View File

@ -0,0 +1,25 @@
package org.hibernate.processor.test.typeliteral;
import java.math.BigDecimal;
import org.hibernate.annotations.processing.CheckHQL;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.NamedQuery;
@Entity(name = "Account")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@CheckHQL
@NamedQuery(name = "#creditAccounts", query = "select a from Account a where type(a) = Credit")
@NamedQuery(name = "#debitAccounts", query = "select a from Account a where type(a) = org.hibernate.processor.test.typeliteral.DebitAccount")
public class Account {
@Id
private Long id;
private String owner;
private BigDecimal balance;
private BigDecimal interestRate;
//Getters and setters are omitted for brevity
}

View File

@ -0,0 +1,11 @@
package org.hibernate.processor.test.typeliteral;
import java.math.BigDecimal;
import jakarta.persistence.Entity;
@Entity(name = "Credit")
public class CreditAccount extends Account {
private BigDecimal creditLimit;
//Getters and setters are omitted for brevity
}

View File

@ -0,0 +1,11 @@
package org.hibernate.processor.test.typeliteral;
import java.math.BigDecimal;
import jakarta.persistence.Entity;
@Entity(name = "Debit")
public class DebitAccount extends Account {
private BigDecimal overdraftFee;
//Getters and setters are omitted for brevity
}

View File

@ -1,17 +0,0 @@
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;
}