-->
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.  [ 4 posts ] 
Author Message
 Post subject: [HQL] Using a "like" comparison in a Map Collectio
PostPosted: Mon Feb 13, 2006 2:32 pm 
Newbie

Joined: Mon Feb 13, 2006 2:20 pm
Posts: 2
Hello all,

This is the setup: In my Document object, I have a collection (title) which consists of String map keys and String values. The object is stored on a database via a hibernate 3 persistence:

<class name="Document" table="WG_DOCUMENTOS">
<cache usage="read-write"/>
<id name="id" type="java.lang.Integer">
<generator class="increment"/>
</id>
<property name="fecha_creacion"/>
<map name="title" table="WG_DOCUMENTOS_TITULOS">
<key column="DOC"/>
<map-key type="java.lang.String" column="LANG"/>
<element type="text" column="TITLE"/>
</map>
</class>

I need to get the Document objects with a title like a given string. I can do it with "where ? in elements(title)", but I need to use a ilike comparison (case insensitive and %-pattern-matching). How do I do that in HQL? any clue? I'm new to HQL and it looks so powerful that it's hard to fully understand its principles..


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 5:51 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
HQL doesn't support ilike. Criteria do, but not HQL. This is how to do it in HQL:
Code:
select d from Document d
  join d.Title t
  where t.Text like lower(:TitleSearchText)
Then you just have to use qry.setString(searchTitle.toLowerCase());


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 6:03 pm 
Newbie

Joined: Mon Feb 13, 2006 2:20 pm
Posts: 2
Thanks..

If it's not a big deal, how would you handle that same query with criteria querys?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 6:14 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Something along these lines:
Code:
Criteria crit = session.createCriteria(Document.class);
crit.createCriteria("title").add(Restictions.ilike("text", searchString, MatchMode.ANYWHERE));
List docs = crit.list();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.