From 1c1fe2a9af476367a105ee24e4ba7b97b22f40c8 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Fri, 7 Oct 2016 15:17:49 +0200 Subject: [PATCH] HHH-11159 - Add test for issue --- .../nulliteral/NullLiteralExpression.java | 54 +++++++++++++++++++ .../jpa/test/criteria/nulliteral/Person.java | 25 +++++++++ .../jpa/test/criteria/nulliteral/Subject.java | 23 ++++++++ 3 files changed, 102 insertions(+) create mode 100644 hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/NullLiteralExpression.java create mode 100644 hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/Person.java create mode 100644 hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/Subject.java diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/NullLiteralExpression.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/NullLiteralExpression.java new file mode 100644 index 0000000000..bc42de81ca --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/NullLiteralExpression.java @@ -0,0 +1,54 @@ +/* + * 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 . + */ +package org.hibernate.jpa.test.criteria.nulliteral; + +import javax.persistence.EntityManager; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaUpdate; + +import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; + +import org.hibernate.testing.TestForIssue; +import org.junit.Test; + +/** + * @author Andrea Boriero + */ +public class NullLiteralExpression extends BaseEntityManagerFunctionalTestCase { + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] {Person.class, Subject.class}; + } + + @Test + @TestForIssue( jiraKey = "HHH-11159") + public void testNullLiteralExpressionInCriteriaUpdate() { + EntityManager entityManager = getOrCreateEntityManager(); + try { + entityManager.getTransaction().begin(); + + CriteriaBuilder builder = entityManager.getCriteriaBuilder(); + CriteriaUpdate criteriaUpdate = builder.createCriteriaUpdate( 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(); + } + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/Person.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/Person.java new file mode 100644 index 0000000000..be3a0377df --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/Person.java @@ -0,0 +1,25 @@ +/* + * 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 . + */ +package org.hibernate.jpa.test.criteria.nulliteral; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +/** + * @author Andrea Boriero + */ +@Entity +public class Person { + @Id + @GeneratedValue + private long id; + + @ManyToOne + private Subject subject; +} diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/Subject.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/Subject.java new file mode 100644 index 0000000000..c9da16c612 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/Subject.java @@ -0,0 +1,23 @@ +/* + * 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 . + */ +package org.hibernate.jpa.test.criteria.nulliteral; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +/** + * @author Andrea Boriero + */ +@Entity +public class Subject { + @Id + @GeneratedValue + private long id; + + private String name; +}