Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

isNotNull & isNotEmpty Hibernate

 
Thalys de Aguiar Gomes
Greenhorn
Posts: 15
Eclipse IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
People need to have this list only the objects that this description field is not null and void... that there's more code giving ...

org.hibernate.MappingException: Property path [ClienteTO.description] does not reference a collection

If I shot this isNotNull and isNotEmpty he has much work to some customers who have ..... field null and I do not want that




someone could help me...
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Tabajara"

Please check your private message for a message from JavaRanch.
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
criteria.add(Restrictions.isNotEmpty("description"));


The isNotEmpty restriction is meant for collections. Here's a comment from the javadoc:

Constrain a collection valued property to be non-empty


If you want to check the "description", which i guess is a String, is not an empty string, then you could do this instead:

 
Stephane Eybert
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May I suggest you also check for the possibility of a null value ?

So, instead of having:

criteria.add(Restrictions.ne("description",""));

you could have:

criteria.add(Restrictions.and(Restrictions.ne("description",""), Restrictions.isNotNull("description")));
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic