-->
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: Using Map entry values in a Criteria query
PostPosted: Tue Mar 20, 2007 12:47 pm 
Newbie

Joined: Tue Mar 20, 2007 12:13 pm
Posts: 2
Hi,

I'm trying to make a query that looks at certain values in a map. For example the map could contain:

key;"key" value:"value"

And then I want to include the value in an equals expression. This works using Criteria.createCriteria() when the association is another class, but I can't get it to work with a map as mapped below. Any Ideas?

Thanks in advance,
Ivo

Hibernate version: 3.1.3

Mapping documents:
Code:
<hibernate-mapping package="org.openprojectservices">
   <class name="Event" table="event">
   
        <!-- left the rest out -->

         <map name="xProps" cascade="all" table="event_xProps" order-by="xprop_name" lazy="false">
          <key column="id"/>
          <map-key column="xprop_name" type="string"/>
          <element column="xprop_value" type="string"/>
      </map>
      
   </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
Criteria criteria = getSession().createCriteria(Event.class);
Criteria xPropsCriteria = criteria.createCriteria("xProps");

Full stack trace of any exception that occurs:
Code:
org.hibernate.MappingException: collection was not an association: org.openprojectservices.Event.xProps
   at org.hibernate.type.CollectionType.getAssociatedEntityName(CollectionType.java:380)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.getPathEntityName(CriteriaQueryTranslator.java:207)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.createCriteriaEntityNameMap(CriteriaQueryTranslator.java:191)
   at org.hibernate.loader.criteria.CriteriaQueryTranslator.<init>(CriteriaQueryTranslator.java:81)
   at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:58)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1514)
   at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
   at org.openprojectservices.dao.impl.EventDaoHibernateImpl.getEvents(EventDaoHibernateImpl.java:29)
   at org.webical.dao.EventDaoHibernateimplTest.testGetEventsForProjectGUIDList(EventDaoHibernateimplTest.java:103)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
   at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


Name and version of the database you are using:
HSQLDB 1.8.0

_________________
Ivo van Dongen
Func. Internet Integration
W http://www.func.nl
T +31 20 4230000
F +31 20 4223500


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 1:04 pm 
Newbie

Joined: Mon Aug 14, 2006 8:59 pm
Posts: 2
I've run smack into this same problem, with equally unproductive results. Is this just a non-starter, or do I have a serious mental block? Any wisdom out there?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 1:13 pm 
Newbie

Joined: Tue Mar 20, 2007 12:13 pm
Posts: 2
Well I didn't find a way to do this, so I've just created a class for the map and mapped it in hibernate. That works great off course, but it does seem a bit overdone. I'd really like to know if there is a way to this some other way.

Regards,
Ivo

_________________
Ivo van Dongen
Func. Internet Integration
W http://www.func.nl
T +31 20 4230000
F +31 20 4223500


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.