-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: CriteriaUpdate set field to null?
PostPosted: Mon Apr 14, 2014 2:45 pm 
Newbie

Joined: Mon Apr 14, 2014 2:37 pm
Posts: 1
I'm trying to perform a bulk update with JPA 2.1 CriteriaUpdate in Hibernate 4.3.0.GA, but have not found how to set a field to null.

The code is structured like this - I'd like to set a nullable field back to null.

CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaUpdate<User> q = cb.createCriteriaUpdate(User.class);
Address nullAddress = null;
q.set(PushUser_.altAddress, nullAddress);
Root<User> userRoot = q.from(User.class);
q.where(userRoot.get(User_.userId).in(userIdList));
int count = em.createQuery(q).executeUpdate();

I get this exception from the q.set() call setting null:
Exception in thread "Thread-1" java.lang.NullPointerException
at org.hibernate.jpa.criteria.CriteriaUpdateImpl.set(CriteriaUpdateImpl.java:87)

What's the correct way to do this?


Top
 Profile  
 
 Post subject: Re: CriteriaUpdate set field to null?
PostPosted: Mon Jun 02, 2014 11:23 am 
Newbie

Joined: Mon Jun 02, 2014 11:18 am
Posts: 1
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaUpdate<User> q = cb.createCriteriaUpdate(User.class);
Expression<Address> nullAddress = cb.nullLiteral(Address.class);
q.set(PushUser_.altAddress, nullAddress);
Root<User> userRoot = q.from(User.class);
q.where(userRoot.get(User_.userId).in(userIdList));
int count = em.createQuery(q).executeUpdate();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.