HHH-18007 Add a testcase for the issue
This commit is contained in:
parent
47b63e51b9
commit
e036509487
|
@ -7,44 +7,90 @@
|
||||||
package org.hibernate.orm.test.mapping;
|
package org.hibernate.orm.test.mapping;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
|
import org.hibernate.testing.orm.junit.Jira;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.junit.jupiter.api.AfterAll;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.IdClass;
|
import jakarta.persistence.IdClass;
|
||||||
import jakarta.persistence.MappedSuperclass;
|
import jakarta.persistence.MappedSuperclass;
|
||||||
|
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||||
|
import jakarta.persistence.criteria.CriteriaQuery;
|
||||||
|
import jakarta.persistence.criteria.Path;
|
||||||
|
import jakarta.persistence.criteria.Root;
|
||||||
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import org.hibernate.testing.orm.junit.DomainModel;
|
|
||||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
@TestForIssue(jiraKey = "HHH-14499")
|
|
||||||
@DomainModel(
|
@DomainModel(
|
||||||
annotatedClasses = {
|
annotatedClasses = {
|
||||||
MappedSuperclassWithGenericsTest.IntermediateAbstractMapped.class,
|
MappedSuperclassWithGenericsTest.IntermediateAbstractMapped.class,
|
||||||
MappedSuperclassWithGenericsTest.BaseEntity.class,
|
MappedSuperclassWithGenericsTest.BaseEntity.class,
|
||||||
MappedSuperclassWithGenericsTest.AbstractGenericMappedSuperType.class,
|
MappedSuperclassWithGenericsTest.AbstractGenericMappedSuperType.class,
|
||||||
|
MappedSuperclassWithGenericsTest.SimpleEntity.class,
|
||||||
|
MappedSuperclassWithGenericsTest.GenericIdBaseEntity.class
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@SessionFactory
|
@SessionFactory
|
||||||
public class MappedSuperclassWithGenericsTest {
|
public class MappedSuperclassWithGenericsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Jira( "https://hibernate.atlassian.net/browse/HHH-14499" )
|
||||||
public void testIt() {
|
public void testIt() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@MappedSuperclass
|
@Test
|
||||||
public static abstract class AbstractGenericMappedSuperType<T> {
|
@Jira( "https://hibernate.atlassian.net/browse/HHH-18007" )
|
||||||
|
void testSelectCriteriaGenericId(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( session -> {
|
||||||
|
final CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
|
||||||
|
final CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery( Long.class );
|
||||||
|
final Root<SimpleEntity> root = criteriaQuery.from( SimpleEntity.class );
|
||||||
|
final Path<Long> idPath = root.get( "id" );
|
||||||
|
criteriaQuery.select( idPath );
|
||||||
|
final List<Long> resultList = session.createQuery( criteriaQuery ).getResultList();
|
||||||
|
assertThat( resultList ).hasSize( 1 ).containsOnly( 1L );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
private T whateverType;
|
@Test
|
||||||
|
@Jira( "https://hibernate.atlassian.net/browse/HHH-18007" )
|
||||||
|
void testSelectGenericId(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( session -> {
|
||||||
|
final List<Long> resultList = session.createQuery(
|
||||||
|
"select e.id from SimpleEntity e",
|
||||||
|
Long.class
|
||||||
|
).getResultList();
|
||||||
|
assertThat( resultList ).hasSize( 1 ).containsOnly( 1L );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
public void setUp(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( session -> session.persist( new SimpleEntity( 1L, "simple_1" ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
public void tearDown(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( session -> session.createMutationQuery( "delete from SimpleEntity" ).executeUpdate() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
@IdClass(PK.class)
|
public static abstract class AbstractGenericMappedSuperType<T> {
|
||||||
public static abstract class IntermediateAbstractMapped<T> extends AbstractGenericMappedSuperType<T> {
|
private T whateverType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@MappedSuperclass
|
||||||
|
@IdClass( PK.class )
|
||||||
|
public static abstract class IntermediateAbstractMapped<T> extends AbstractGenericMappedSuperType<T> {
|
||||||
@Id
|
@Id
|
||||||
private String keyOne;
|
private String keyOne;
|
||||||
@Id
|
@Id
|
||||||
|
@ -53,9 +99,8 @@ public class MappedSuperclassWithGenericsTest {
|
||||||
private String keyThree;
|
private String keyThree;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("UnusedDeclaration")
|
@SuppressWarnings( "UnusedDeclaration" )
|
||||||
public static class PK implements Serializable {
|
public static class PK implements Serializable {
|
||||||
|
|
||||||
private String keyOne;
|
private String keyOne;
|
||||||
private String keyTwo;
|
private String keyTwo;
|
||||||
private String keyThree;
|
private String keyThree;
|
||||||
|
@ -80,11 +125,37 @@ public class MappedSuperclassWithGenericsTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(name = "BaseEntity")
|
@Entity( name = "BaseEntity" )
|
||||||
public static class BaseEntity<T> extends IntermediateAbstractMapped<byte[]> {
|
public static class BaseEntity<T> extends IntermediateAbstractMapped<byte[]> {
|
||||||
|
|
||||||
String aString;
|
String aString;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MappedSuperclass
|
||||||
|
public static class GenericIdBaseEntity<T extends Serializable> {
|
||||||
|
@Id
|
||||||
|
private T id;
|
||||||
|
|
||||||
|
protected GenericIdBaseEntity(T id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Entity( name = "SimpleEntity" )
|
||||||
|
public static class SimpleEntity extends GenericIdBaseEntity<Long> {
|
||||||
|
@Column
|
||||||
|
private String string;
|
||||||
|
|
||||||
|
public SimpleEntity() {
|
||||||
|
super( null );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SimpleEntity(Long id, String string) {
|
||||||
|
super( id );
|
||||||
|
this.string = string;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue