HHH-16803 Add test for issue

This commit is contained in:
Marco Belladelli 2023-06-28 09:59:59 +02:00
parent 147f01ac0b
commit 9f1239ce77
3 changed files with 42 additions and 24 deletions

View File

@ -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
}

View File

@ -6,14 +6,15 @@
*/ */
package org.hibernate.orm.test.jpa.criteria.nulliteral; 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.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaUpdate; import jakarta.persistence.criteria.CriteriaUpdate;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase; import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
/** /**
* @author Andrea Boriero * @author Andrea Boriero
@ -22,33 +23,30 @@ public class NullLiteralExpression extends BaseEntityManagerFunctionalTestCase {
@Override @Override
protected Class<?>[] getAnnotatedClasses() { protected Class<?>[] getAnnotatedClasses() {
return new Class[] {Person.class, Subject.class}; return new Class[] { Person.class, Subject.class };
} }
@Test @Test
@TestForIssue( jiraKey = "HHH-11159") @Jira( "https://hibernate.atlassian.net/browse/HHH-11159" )
public void testNullLiteralExpressionInCriteriaUpdate() { public void testNullLiteralExpressionInCriteriaUpdate() {
EntityManager entityManager = getOrCreateEntityManager(); doInJPA( this::entityManagerFactory, entityManager -> {
try {
entityManager.getTransaction().begin();
CriteriaBuilder builder = entityManager.getCriteriaBuilder(); CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaUpdate<Person> criteriaUpdate = builder.createCriteriaUpdate( Person.class ); CriteriaUpdate<Person> criteriaUpdate = builder.createCriteriaUpdate( Person.class );
criteriaUpdate.from(Person.class); criteriaUpdate.from( Person.class );
criteriaUpdate.set( Person_.subject, builder.nullLiteral( Subject.class ) ); criteriaUpdate.set( Person_.subject, builder.nullLiteral( Subject.class ) );
entityManager.createQuery( criteriaUpdate ).executeUpdate(); entityManager.createQuery( criteriaUpdate ).executeUpdate();
} );
}
entityManager.getTransaction().commit(); @Test
} @Jira( "https://hibernate.atlassian.net/browse/HHH-16803" )
catch (Exception e) { public void testEnumNullLiteralUpdate() {
if ( entityManager.getTransaction().isActive() ) { doInJPA( this::entityManagerFactory, entityManager -> {
entityManager.getTransaction().rollback(); final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
} final CriteriaUpdate<Person> criteriaUpdate = builder.createCriteriaUpdate( Person.class );
throw e; criteriaUpdate.from( Person.class );
} criteriaUpdate.set( Person_.eyeColor, builder.nullLiteral( EyeColor.class ) );
finally { entityManager.createQuery( criteriaUpdate ).executeUpdate();
entityManager.close(); } );
}
} }
} }

View File

@ -7,6 +7,7 @@
package org.hibernate.orm.test.jpa.criteria.nulliteral; package org.hibernate.orm.test.jpa.criteria.nulliteral;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
@ -22,4 +23,7 @@ public class Person {
@ManyToOne @ManyToOne
private Subject subject; private Subject subject;
@Enumerated
private EyeColor eyeColor;
} }