From 46b27390617ddc0b2d3a62b95cd0f2755e55e072 Mon Sep 17 00:00:00 2001 From: Jan Schatteman Date: Tue, 23 Jul 2024 22:16:16 +0200 Subject: [PATCH] HHH-18373 - Add test for binding null as value in Criteria API Signed-off-by: Jan Schatteman --- .../AbstractMutationStrategyIdTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/bulkid/AbstractMutationStrategyIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/bulkid/AbstractMutationStrategyIdTest.java index c3b6c9265d..76e8f0b141 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/bulkid/AbstractMutationStrategyIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/bulkid/AbstractMutationStrategyIdTest.java @@ -1,16 +1,22 @@ package org.hibernate.orm.test.bulkid; import jakarta.persistence.Entity; +import jakarta.persistence.EntityManager; import jakarta.persistence.GeneratedValue; import jakarta.persistence.Id; import jakarta.persistence.Inheritance; import jakarta.persistence.InheritanceType; +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.CriteriaUpdate; +import jakarta.persistence.criteria.Root; import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.Configuration; +import org.hibernate.orm.test.jpa.compliance.CriteriaMutationQueryTableTest; import org.hibernate.query.sqm.mutation.spi.SqmMultiTableMutationStrategy; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.hibernate.testing.orm.junit.Jira; import org.junit.Before; import org.junit.Test; @@ -90,6 +96,22 @@ public abstract class AbstractMutationStrategyIdTest extends BaseCoreFunctionalT }); } + @Test + @Jira( value = "HHH-18373" ) + public void testNullValueUpdateWithCriteria() { + doInHibernate( this::sessionFactory, session -> { + EntityManager entityManager = session.unwrap( EntityManager.class); + + CriteriaBuilder cb = entityManager.getCriteriaBuilder(); + CriteriaUpdate update = cb.createCriteriaUpdate( Person.class ).set( "name", null ); + Root person = update.from( Person.class ); + update.where( cb.equal( person.get( "employed" ), true ) ); + int updateCount = entityManager.createQuery( update ).executeUpdate(); + + assertEquals( entityCount(), updateCount ); + }); + } + @Test public void testDeleteFromPerson() { doInHibernate( this::sessionFactory, session -> {