1212import java .util .List ;
1313import java .util .Map ;
1414
15- import com .fasterxml .jackson .databind .JsonNode ;
16- import jakarta .json .JsonValue ;
1715import org .hibernate .annotations .JdbcTypeCode ;
1816import org .hibernate .cfg .AvailableSettings ;
1917import org .hibernate .community .dialect .AltibaseDialect ;
2018import org .hibernate .dialect .AbstractHANADialect ;
2119import org .hibernate .dialect .DerbyDialect ;
2220import org .hibernate .dialect .OracleDialect ;
23- import org .hibernate .dialect .PostgreSQLDialect ;
2421import org .hibernate .dialect .SybaseDialect ;
2522import org .hibernate .metamodel .mapping .internal .BasicAttributeMapping ;
2623import org .hibernate .metamodel .spi .MappingMetamodelImplementor ;
2724import org .hibernate .persister .entity .EntityPersister ;
28- import org .hibernate .testing .orm .junit .RequiresDialect ;
25+ import org .hibernate .query .MutationQuery ;
26+ import org .hibernate .query .criteria .HibernateCriteriaBuilder ;
2927import org .hibernate .type .SqlTypes ;
3028import org .hibernate .type .descriptor .jdbc .JdbcType ;
3129import org .hibernate .type .descriptor .jdbc .spi .JdbcTypeRegistry ;
3230
3331import org .hibernate .testing .orm .junit .DomainModel ;
32+ import org .hibernate .testing .orm .junit .Jira ;
3433import org .hibernate .testing .orm .junit .JiraKey ;
3534import org .hibernate .testing .orm .junit .ServiceRegistry ;
3635import org .hibernate .testing .orm .junit .SessionFactory ;
4140import org .junit .jupiter .api .BeforeEach ;
4241import org .junit .jupiter .api .Test ;
4342
43+ import com .fasterxml .jackson .databind .JsonNode ;
44+ import jakarta .json .JsonValue ;
4445import jakarta .persistence .Entity ;
4546import jakarta .persistence .Id ;
4647import jakarta .persistence .Table ;
48+ import jakarta .persistence .criteria .CriteriaUpdate ;
49+ import jakarta .persistence .criteria .Root ;
4750
4851import static org .hamcrest .MatcherAssert .assertThat ;
4952import static org .hamcrest .Matchers .equalTo ;
5053import static org .hamcrest .Matchers .is ;
51- import static org .hamcrest .Matchers .isOneOf ;
5254import static org .hamcrest .Matchers .isA ;
55+ import static org .hamcrest .Matchers .isOneOf ;
5356import static org .hamcrest .Matchers .notNullValue ;
5457import static org .hamcrest .Matchers .nullValue ;
5558
@@ -124,7 +127,8 @@ public void verifyMappings(SessionFactoryScope scope) {
124127 "objectMap" );
125128 final BasicAttributeMapping listAttribute = (BasicAttributeMapping ) entityDescriptor .findAttributeMapping (
126129 "list" );
127- final BasicAttributeMapping jsonAttribute = (BasicAttributeMapping ) entityDescriptor .findAttributeMapping ( "jsonString" );
130+ final BasicAttributeMapping jsonAttribute = (BasicAttributeMapping ) entityDescriptor .findAttributeMapping (
131+ "jsonString" );
128132
129133 assertThat ( stringMapAttribute .getJavaType ().getJavaTypeClass (), equalTo ( Map .class ) );
130134 assertThat ( objectMapAttribute .getJavaType ().getJavaTypeClass (), equalTo ( Map .class ) );
@@ -146,8 +150,8 @@ public void verifyReadWorks(SessionFactoryScope scope) {
146150 assertThat ( entityWithJson .stringMap , is ( stringMap ) );
147151 assertThat ( entityWithJson .objectMap , is ( objectMap ) );
148152 assertThat ( entityWithJson .list , is ( list ) );
149- assertThat ( entityWithJson .jsonNode , is ( nullValue () ));
150- assertThat ( entityWithJson .jsonValue , is ( nullValue () ));
153+ assertThat ( entityWithJson .jsonNode , is ( nullValue () ) );
154+ assertThat ( entityWithJson .jsonValue , is ( nullValue () ) );
151155 }
152156 );
153157 }
@@ -167,14 +171,14 @@ public void verifyMergeWorks(SessionFactoryScope scope) {
167171 assertThat ( entityWithJson .objectMap , is ( nullValue () ) );
168172 assertThat ( entityWithJson .list , is ( nullValue () ) );
169173 assertThat ( entityWithJson .jsonString , is ( nullValue () ) );
170- assertThat ( entityWithJson .jsonNode , is ( nullValue () ));
171- assertThat ( entityWithJson .jsonValue , is ( nullValue () ));
174+ assertThat ( entityWithJson .jsonNode , is ( nullValue () ) );
175+ assertThat ( entityWithJson .jsonValue , is ( nullValue () ) );
172176 }
173177 );
174178 }
175179
176180 @ Test
177- @ JiraKey ( "HHH-16682" )
181+ @ JiraKey ("HHH-16682" )
178182 public void verifyDirtyChecking (SessionFactoryScope scope ) {
179183 scope .inTransaction (
180184 (session ) -> {
@@ -198,7 +202,7 @@ public void verifyDirtyChecking(SessionFactoryScope scope) {
198202 @ SkipForDialect (dialectClass = AltibaseDialect .class , reason = "Altibase doesn't support comparing CLOBs with the = operator" )
199203 public void verifyComparisonWorks (SessionFactoryScope scope ) {
200204 scope .inTransaction (
201- (session ) -> {
205+ (session ) -> {
202206 // PostgreSQL returns the JSON slightly formatted
203207 String alternativeJson = "{\" name\" : \" abc\" }" ;
204208 EntityWithJson entityWithJson = session .createQuery (
@@ -243,6 +247,32 @@ else if ( nativeJson instanceof Clob ) {
243247 );
244248 }
245249
250+ @ Test
251+ @ Jira ("https://hibernate.atlassian.net/browse/HHH-18709" )
252+ public void verifyCriteriaUpdateQueryWorks (SessionFactoryScope scope ) {
253+ final Map <String , String > newMap = Map .of ( "name" , "ABC" );
254+ final List <StringNode > newList = List .of ( new StringNode ( "ABC" ) );
255+ final String newJson = "{\" count\" :123}" ;
256+ scope .inTransaction ( session -> {
257+ final HibernateCriteriaBuilder builder = session .getCriteriaBuilder ();
258+ final CriteriaUpdate <EntityWithJson > criteria = builder .createCriteriaUpdate ( EntityWithJson .class );
259+ final Root <EntityWithJson > root = criteria .from ( EntityWithJson .class );
260+ criteria .set ( root .get ( "stringMap" ), newMap );
261+ criteria .set ( "list" , newList );
262+ criteria .set ( root .get ( "jsonString" ), newJson );
263+ criteria .where ( builder .equal ( root .get ( "id" ), 1 ) );
264+ final MutationQuery query = session .createMutationQuery ( criteria );
265+ final int count = query .executeUpdate ();
266+ assertThat ( count , is ( 1 ) );
267+ } );
268+ scope .inSession ( session -> {
269+ final EntityWithJson entityWithJson = session .find ( EntityWithJson .class , 1 );
270+ assertThat ( entityWithJson .stringMap , is ( newMap ) );
271+ assertThat ( entityWithJson .list , is ( newList ) );
272+ assertThat ( entityWithJson .jsonString .replaceAll ( "\\ s" , "" ), is ( newJson ) );
273+ } );
274+ }
275+
246276 @ Entity (name = "EntityWithJson" )
247277 @ Table (name = "EntityWithJson" )
248278 public static class EntityWithJson {
0 commit comments