HHH-16023 Add test for issue

This commit is contained in:
Marco Belladelli 2023-01-17 15:45:57 +01:00 committed by Christian Beikov
parent ae37509b11
commit 64b3855c73
1 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,100 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.jpa.ql;
import java.util.List;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.DiscriminatorColumn;
import jakarta.persistence.DiscriminatorType;
import jakarta.persistence.DiscriminatorValue;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
import jakarta.persistence.InheritanceType;
import jakarta.persistence.NamedNativeQueries;
import jakarta.persistence.NamedNativeQuery;
import jakarta.persistence.Table;
import static org.junit.jupiter.api.Assertions.assertNotNull;
/**
* @author Marco Belladelli
*/
@DomainModel(annotatedClasses = {
NamedNativeQueryWithGenericsTest.MyEntity.class,
NamedNativeQueryWithGenericsTest.EntityType.class
})
@SessionFactory
@JiraKey("HHH-16023")
public class NamedNativeQueryWithGenericsTest {
@Test
public void testNamedNativeQuery(SessionFactoryScope scope) {
scope.inTransaction( session -> {
List myEntities = session.getNamedNativeQuery( "MyEntity.findMyEntity" )
.addEntity( "ame", MyEntity.class )
.getResultList();
assertNotNull( myEntities );
} );
}
@NamedNativeQueries(value = {
@NamedNativeQuery(
name = "MyEntity.findMyEntity",
query = "WITH RECURSIVE all_my_entities AS " +
"(SELECT me.* FROM my_entity me) " +
"SELECT {ame.*} FROM all_my_entities ame")
})
@Entity(name = "my_entity")
@Table(name = "my_entity")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING, name = "entity_type")
public static class MyEntity<E extends MyEntity> {
@Id
@GeneratedValue
private Long id;
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Entity
@DiscriminatorValue("SUPPORTING_ASSET_TYPE")
public static class EntityType extends MyEntity<EntityType> {
private String additionalProp;
public String getAdditionalProp() {
return additionalProp;
}
public void setAdditionalProp(String additionalProp) {
this.additionalProp = additionalProp;
}
}
}