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