HHH-18373 - Add test for binding null as value in Criteria API

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2024-07-23 22:16:16 +02:00 committed by Christian Beikov
parent abc4d5ba9e
commit 46b2739061
1 changed files with 22 additions and 0 deletions

View File

@ -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<Person> update = cb.createCriteriaUpdate( Person.class ).set( "name", null );
Root<Person> 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 -> {