HHH-17671 - Add test for issue

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2024-01-31 00:19:06 +01:00 committed by Christian Beikov
parent 67f573a6bf
commit 21d3ea4ea8
1 changed files with 21 additions and 0 deletions

View File

@ -8,8 +8,13 @@ package org.hibernate.orm.test.jpa.compliance;
import java.util.List;
import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.query.sqm.tree.predicate.SqmPredicate;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.Jpa;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
@ -18,6 +23,7 @@ import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -69,6 +75,21 @@ public class CriteriaIsNullTest {
}
@Test
@JiraKey( "HHH-17671" )
public void testPredicateCopy(EntityManagerFactoryScope scope) {
scope.inEntityManager(
entityManager -> {
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Account> c = builder.createQuery(Account.class);
Root<Account> r = c.from(Account.class);
Predicate predicate = builder.isNull( r.get( "amount"));
c.where(predicate);
Assertions.assertDoesNotThrow( () -> ( (SqmPredicate) c.getRestriction() ).copy( SqmCopyContext.simpleContext()) );
}
);
}
@Entity(name = "Person")
public static class Person {