From 9f1239ce775f1c3569a1eb670da2033eeddfb0fa Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Wed, 28 Jun 2023 09:59:59 +0200 Subject: [PATCH] HHH-16803 Add test for issue --- .../jpa/criteria/nulliteral/EyeColor.java | 16 +++++++ .../nulliteral/NullLiteralExpression.java | 46 +++++++++---------- .../test/jpa/criteria/nulliteral/Person.java | 4 ++ 3 files changed, 42 insertions(+), 24 deletions(-) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/nulliteral/EyeColor.java diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/nulliteral/EyeColor.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/nulliteral/EyeColor.java new file mode 100644 index 0000000000..ef89f351a7 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/nulliteral/EyeColor.java @@ -0,0 +1,16 @@ +/* + * 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.criteria.nulliteral; + +/** + * @author Marco Belladelli + */ +public enum EyeColor { + BROWN, + GREEN, + BLUE +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/nulliteral/NullLiteralExpression.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/nulliteral/NullLiteralExpression.java index 77488bd60d..5349b0a610 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/nulliteral/NullLiteralExpression.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/nulliteral/NullLiteralExpression.java @@ -6,14 +6,15 @@ */ package org.hibernate.orm.test.jpa.criteria.nulliteral; -import jakarta.persistence.EntityManager; +import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; + +import org.hibernate.testing.orm.junit.Jira; +import org.junit.Test; + import jakarta.persistence.criteria.CriteriaBuilder; import jakarta.persistence.criteria.CriteriaUpdate; -import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; - -import org.hibernate.testing.TestForIssue; -import org.junit.Test; +import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; /** * @author Andrea Boriero @@ -22,33 +23,30 @@ public class NullLiteralExpression extends BaseEntityManagerFunctionalTestCase { @Override protected Class[] getAnnotatedClasses() { - return new Class[] {Person.class, Subject.class}; + return new Class[] { Person.class, Subject.class }; } @Test - @TestForIssue( jiraKey = "HHH-11159") + @Jira( "https://hibernate.atlassian.net/browse/HHH-11159" ) public void testNullLiteralExpressionInCriteriaUpdate() { - EntityManager entityManager = getOrCreateEntityManager(); - try { - entityManager.getTransaction().begin(); - + doInJPA( this::entityManagerFactory, entityManager -> { CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaUpdate criteriaUpdate = builder.createCriteriaUpdate( Person.class ); - criteriaUpdate.from(Person.class); + criteriaUpdate.from( Person.class ); criteriaUpdate.set( Person_.subject, builder.nullLiteral( Subject.class ) ); - entityManager.createQuery( criteriaUpdate ).executeUpdate(); + } ); + } - entityManager.getTransaction().commit(); - } - catch (Exception e) { - if ( entityManager.getTransaction().isActive() ) { - entityManager.getTransaction().rollback(); - } - throw e; - } - finally { - entityManager.close(); - } + @Test + @Jira( "https://hibernate.atlassian.net/browse/HHH-16803" ) + public void testEnumNullLiteralUpdate() { + doInJPA( this::entityManagerFactory, entityManager -> { + final CriteriaBuilder builder = entityManager.getCriteriaBuilder(); + final CriteriaUpdate criteriaUpdate = builder.createCriteriaUpdate( Person.class ); + criteriaUpdate.from( Person.class ); + criteriaUpdate.set( Person_.eyeColor, builder.nullLiteral( EyeColor.class ) ); + entityManager.createQuery( criteriaUpdate ).executeUpdate(); + } ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/nulliteral/Person.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/nulliteral/Person.java index 7a04e64ffe..28734da8d1 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/nulliteral/Person.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/criteria/nulliteral/Person.java @@ -7,6 +7,7 @@ package org.hibernate.orm.test.jpa.criteria.nulliteral; import jakarta.persistence.Entity; +import jakarta.persistence.Enumerated; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.ManyToOne; @@ -22,4 +23,7 @@ public class Person { @ManyToOne private Subject subject; + + @Enumerated + private EyeColor eyeColor; }