Hi,
I have a many-to-many association (Category<->Items). If I look for a Category by Id I get a correct filled Category instance returned with all
available Items in this Category, on the other hand if I search for an item I get the correct filled Item instance with all associated categories back.
Therefore I guess my mapping is correct.
The problem I encounter is, when I look for a Category and Items which only match a certain description I get the correct number of rows back in the List, but the List objects are not Item objects but java.lang.Objects.
Here is my lookup method.
Code:
public List getCategoryItemsByDescr( long catId, String descr )
{
return getHibernateTemplate().find( "from Category cat, Item item where cat.id = ? and item.name like ?", new Object[] { new Long( catId ), "%" + descr + "%" } );
}
I checked the debug log messages and executed the generated sql, the result was correct.
Why are my objects in the List not Item instances?I think my mapping is correct, but I cannot figure out what I am doing wrong.
Any help greatly appreciated.
Thanks,
juergen
P.S.: Just in case, this is my mapping:
Code:
<class name="com.openshop.pizzashop.domain.Category" table="category">
<id name="id" type="long" unsaved-value="-1">
<column name="id" sql-type="number" not-null="true"/>
<generator class="identity"/>
</id>
<property name="descr">
<column name="descr" sql-type="varchar(30)"/>
</property>
<set name="items" table="link">
<key>
<column name="catno" not-null="true"/>
</key>
<many-to-many class="com.openshop.pizzashop.domain.Item">
<column name="artno" not-null="true"/>
</many-to-many>
</set>
</class>
<class name="com.openshop.pizzashop.domain.Item" table="items">
<id name="id" type="long" unsaved-value="-1">
<column name="itemid" sql-type="number" not-null="true"/>
<generator class="identity"/>
</id>
<property name="name">
<column name="product" sql-type="varchar(50)"/>
</property>
<property name="descr">
<column name="description" sql-type="varchar(255)"/>
</property>
<property name="price">
<column name="price" sql-type="varchar(20)"/>
</property>
<property name="tax">
<column name="tax" sql-type="number"/>
</property>
<property name="picture">
<column name="picture" sql-type="varchar(100)"/>
</property>
<property name="cmsId">
<column name="cms_id" sql-type="varchar(50)"/>
</property>
<set name="catIds" table="link">
<key>
<column name="artno" not-null="true"/>
</key>
<many-to-many class="com.openshop.pizzashop.domain.Category">
<column name="catno" not-null="true"/>
</many-to-many>
</set>
</class>