-->
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: Wildcard search (like *searchstring*) to filter a set
PostPosted: Tue Mar 09, 2010 11:07 am 
Newbie

Joined: Tue Mar 09, 2010 10:57 am
Posts: 2
Hi all,

I have a one-to-many association so that a parent holds a collection of child objects and i want only to return these parents who have a child in the collection according to a specific name. But not only "Test" should return the parent but also "es".

class Parent{ public Set getChildren() }
class Child{ String name; }

<set name="children" inverse="true">
<one-to-many class="Child"/>
<filter name="childNameFilter" condition=":childNameFilterParam like name"/>
</set>

<filter-def name="childNameFilter">
<filter-param name="childNameFilterParam" type="string"/>
</filter-def>

public List getHistory() {
String hql = "from parent as p where size(p.children) >= 1";
HibernateUtil.currentSession().enableFilter("childNameFilter").setParameter("childNameFilterParam", "%es%");
Query query = HibernateUtil.currentSession().createQuery(hql);
}

Unfortunately I don't get any results for '%es%' search patterns. Any help appreciated! Thx!


Top
 Profile  
 
 Post subject: Re: Wildcard search (like *searchstring*) to filter a set
PostPosted: Tue Mar 09, 2010 3:20 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
The filter condition is incorrect. You should swap the arguments:

Code:
name like :childNameFilterParam


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.