-->
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: Query map contents
PostPosted: Tue Dec 21, 2010 1:26 pm 
Newbie

Joined: Tue Nov 01, 2005 12:38 pm
Posts: 12
Hello,

I got a class named "Event", that contains a field "Map<String,String> attributes", and I want to do a query against values inside the map.

The following works as desired:
Code:
getEventDAO().find("from Event event where event.attributes['NODE'] = 'localhost'");

The method find(String query) uses a Spring HibernateTemplate to execute the query. It works fine, but I can not limit the result size.

I tried using a DetachedCriteria, but I just can't get this working:

Code:
DetachedCriteria query = DetachedCriteria.forClass(Event.class);
query.add(Restrictions.sqlRestriction("{alias}.attributes['NODE'] = 'localhost'"));

It just keeps telling me that "attributes" does not exist. I also tried:
Code:
query.add(Restrictions.eq("attributes['NODE']","localhost"))

But I also only produces exceptions. Any Idea how to handle this? I could not find any useful examples of how to query contents of a Map attribute like that.

Regards,

Sven


Top
 Profile  
 
 Post subject: Re: Query map contents
PostPosted: Tue Dec 21, 2010 5:42 pm 
Regular
Regular

Joined: Wed Feb 15, 2006 9:09 pm
Posts: 76
Does this help at all: viewtopic.php?f=1&t=1008805

What do you mean you can't limit the results? If you wrote your EventDAO yourself, you should be able to do a setMaxResults() call on the Query. You'd need to use a Hibernate session... but hopefully your event DAO is your own code and not just a template reference, so you can encapsulate all your event-related fetching code. Personally I used to extend HibernateDaoSupport (Gives you this.getSession()) before I moved to a more JPA-friendly pattern.


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.