aspose file tools*
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
Author

isNotNull & isNotEmpty Hibernate

Thalys de Aguiar Gomes
Greenhorn

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
Marshal

Joined: Jul 20, 2005
Posts: 10288
    
168

"Tabajara"

Please check your private message for a message from JavaRanch.


[My Blog] [JavaRanch Journal]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10288
    
168

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

Joined: Mar 15, 2010
Posts: 34
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
 
subject: isNotNull & isNotEmpty Hibernate