-->
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.  [ 3 posts ] 
Author Message
 Post subject: Query a java.util.Map with a value
PostPosted: Tue Feb 10, 2009 8:13 pm 
Newbie

Joined: Wed Nov 19, 2008 7:30 pm
Posts: 2
Hello,
I have an Object (call it A) with a Map<String, String> I would like to be able to query using the one of the values of the map to retrieve the Object A.
I have searched quite a bit for an answer but I have not found anything that has worked. Any help is greatly appreciated.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 11, 2009 2:28 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Please refer to

http://forum.hibernate.org/viewtopic.php?p=2182742&sid=5061b1a95bef794c1c8898e4c0bed85f

even though it is about Hibernate 2.0.x, but you can use same thing in Hibernate 3.x .

For following code

Code:
public class A {
   .........
   private Map<String,String> someMap = new HashMap<String,String>();
   .............

}


you can use following queries-

Code:
SELECT a FROM A as a LEFT JOIN a.someMap as map  where map= :value;
SELECT a FROM A as a LEFT JOIN a.someMap as map  where map[:key]= :value;


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Fri Feb 27, 2009 7:15 pm 
Newbie

Joined: Wed Nov 19, 2008 7:30 pm
Posts: 2
Sorry this reply is so late I must not have seen the email notifying me of your response. So the query that worked was:

Code:
SELECT a FROM A as a LEFT JOIN a.someMap as map where map='value';


This is exactly what you posted except that I surrounded the value with single quotes (may actually be equivalent to what you posted for all I know), anyway THANKS A MILLION.


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