Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reproducer: HHH-18007 Creating criteria query for a generic identifier with a @MappedSuperclass leads to an exception #8238

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@
*/
package org.hibernate.orm.test.mapping;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.Serializable;
import java.util.Objects;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
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 org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;

@TestForIssue(jiraKey = "HHH-14499")
Expand All @@ -24,6 +32,8 @@
MappedSuperclassWithGenericsTest.IntermediateAbstractMapped.class,
MappedSuperclassWithGenericsTest.BaseEntity.class,
MappedSuperclassWithGenericsTest.AbstractGenericMappedSuperType.class,
MappedSuperclassWithGenericsTest.SimpleEntity.class,
MappedSuperclassWithGenericsTest.GenericIdBaseEntity.class
}
)
@SessionFactory
Expand All @@ -34,6 +44,25 @@ public void testIt() {

}

@Test
void testSelectCriteriaGenericId(SessionFactoryScope scope) {
scope.inTransaction( session -> {
CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
CriteriaQuery<Long> criteriaQuery = criteriaBuilder.createQuery( Long.class );
Root<SimpleEntity> root = criteriaQuery.from( SimpleEntity.class );
Path<Long> idPath = root.get( "id" );
criteriaQuery.select( idPath );
assertThat( session.createQuery( criteriaQuery ).getResultList() ).isEmpty();
} );
}

@Test
void testSelectGenericId(SessionFactoryScope scope) {
scope.inTransaction( session -> {
assertThat( session.createQuery( "select e.id from SimpleEntity e", Long.class ).getResultList() ).isEmpty();
} );
}

@MappedSuperclass
public static abstract class AbstractGenericMappedSuperType<T> {

Expand Down Expand Up @@ -87,4 +116,34 @@ public static class BaseEntity<T> extends IntermediateAbstractMapped<byte[]> {

}

@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
String string;

public SimpleEntity() {
super( null );
}

protected SimpleEntity(Long id) {
super( id );
}
}

}