File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes isNotNull  & isNotEmpty  Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "isNotNull  & isNotEmpty  Hibernate" Watch "isNotNull  & isNotEmpty  Hibernate" New topic

isNotNull & isNotEmpty Hibernate

Thalys de Aguiar Gomes

Joined: Mar 31, 2008
Posts: 15

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...

SCJP 5 - 74%, SCWCD - 89%, SCBCD in progress
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441


Please check your private message for a message from JavaRanch.

[My Blog] [JavaRanch Journal]
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441


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

Joined: Mar 15, 2010
Posts: 34
May I suggest you also check for the possibility of a null value ?

So, instead of having:


you could have:

criteria.add(Restrictions.and("description",""), Restrictions.isNotNull("description")));
I agree. Here's the link:
subject: isNotNull & isNotEmpty Hibernate
It's not a secret anymore!