-->
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: Java indexOf equivalent in Hibernate?
PostPosted: Tue Dec 30, 2008 8:45 pm 
Newbie

Joined: Fri Nov 21, 2008 3:35 pm
Posts: 12
I need to search through my database for values that have a property that contains an input value. I've been looking through the HQL and Criterion API's and I can't really find anything that meets what I'm looking for.

I basically want to achieve this result:
for (User user : userList) {
if (user.getName().indexOf(value) != -1) addUserToResultList(user);
}


Or this result, pseudo-code in SQL:
SELECT * FROM user WHERE user.name contains(myValue);

Is this possible with Hibernate or do I need to do it in Java?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2008 10:09 pm 
Beginner
Beginner

Joined: Mon Jul 07, 2008 8:07 pm
Posts: 42
criteria.add(Restrictions.like("propertyName", value, MatchMode.ANYWHERE);

Seems to do the trick for me.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.