-->
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 with a Map (2.1b4)
PostPosted: Fri Oct 03, 2003 11:00 pm 
Newbie

Joined: Fri Oct 03, 2003 10:46 pm
Posts: 8
Hello

In a program there is a parent/child relationship.
Now I have to find all parents where a child have a specific name.
This query does the job without a problem:
Code:
  Criteria crit = session.createCriteria(Parent.class);           
  crit.createCriteria("child").add(Expression.like("name", aString));
  List l = crit.list();


Now I try to replace the child object with a map in parent (see mapping below). Is there a way to do the same query with the childMap?

crit.createCriteria("childMap"); crashes with an error:

Code:
An AssertionFailure occured - this may indicate a bug in Hibernate
net.sf.hibernate.AssertionFailure: not an association
   at net.sf.hibernate.collection.CollectionPersister.getElementPersister(CollectionPersister.java:986)
   at net.sf.hibernate.type.PersistentCollectionType.getAssociatedClass(PersistentCollectionType.java:222)



Regards
Ralph

------------------------

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>   
   <class name="dbdemo.Child">
      <id name="id" type="long">
         <generator class="native"/>
      </id>
      <property name="name" length="20" type="string"/>
      <property name="descr" length="20" type="string"/>      
      <many-to-one name="parent" column="parentId" not-null="true" class="dbdemo.Parent"/>
   </class>

</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
   
   <class name="dbdemo.Parent">
      <id name="id" type="long">
         <generator class="native">
         </generator>
      </id>
       <set name="child" cascade="all" inverse="true" lazy="true">
          <key column="parentId"/>
          <one-to-many class="dbdemo.Child"/>
        </set>       
        <map name="childMap" table="childMap" lazy="false" inverse="false">
          <key column="parentId" />
          <index column="name" type="string" length="20" />
          <element column="descr" type="string" length="100" not-null="true" unique="false"/>
        </map>       
   </class>   
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 04, 2003 5:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
collections of values are not currently supported in the Criteria API (silly message though!)

You will have to use HQL for this.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 04, 2003 4:19 pm 
Newbie

Joined: Fri Oct 03, 2003 10:46 pm
Posts: 8
Thanks for answer.

I'm wondering how can I do that with HQL?


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.