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>