-->
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: How to query mapped maps
PostPosted: Sat Oct 14, 2006 8:14 pm 
Newbie

Joined: Sat Oct 14, 2006 8:07 pm
Posts: 2
Hi,

I've looked all around the web and in Hibernate in Action, but I haven't found an answer to this problem.

I have a mapped class Foo which contains a Map called properties. I'd like to query for all Foo where the properties map contains (or does not contain) a key/value pair.

I've tried the following syntax:
Code:
q.add(Expression.eq("properties.foo", "bar"));


(Where "q" is a Criteria object, "properties" is the name of the Map, "foo" is the key I'm interested in, and "bar" is the value I'm interested in."

That generated the following exception:
Code:
org.hibernate.QueryException: could not resolve property: properties.foo


So, how do you write queries against mapped Maps?

Thanks in advance for your help with this, and apologies if I've missed the obvious answer.

--Blake


Top
 Profile  
 
 Post subject: Partial answer
PostPosted: Sat Oct 14, 2006 8:58 pm 
Newbie

Joined: Sat Oct 14, 2006 8:07 pm
Posts: 2
Here's a partial answer to my question:

Code:
Query q = session.createQuery("from Foo f where f.properties['foo'] = 'bar'");


However, I still haven't figured out how to make that work with Criteria.

The following does NOT work:

Code:
Criteria q = session.createCriteria(Foo.class, "f");
         
q.add(Expression.eq("f.properties['foo']", "bar"));
         


The above gives the exception
Code:
could not resolve property: properties['foo'] of: Foo


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.