Simple Spring-Hibernate DAO problem.

I have two tables in the DB, Categories and Products

Category one-to-many Products

Below is the mapping def. and a sneak view of the Product bean:

<hibernate-mapping>

<class name="com.fivestaroffice.databeans.Category" table="categories">

<id name="id" type="int" column="id">

<generator class="native"/>

</id>

<property name="name" column="name"/>

<property name="notes" column="notes"/>

<property name="image" column="image"/>

</class>

</hibernate-mapping>

<hibernate-mapping>

<class name="com.fivestaroffice.databeans.Product" table="products">

<id name="code" type="string" column="code">

<generator class="assigned"/>

</id>

<many-to-one name="parentCate" column="parentCate" class="com.fivestaroffice.databeans.Category"/>

<property name="innerSize" column="innerSize"/>

<property name="pkgsPerCtn" column="pkgsPerCtn"/>

<property name="unitPrice" column="unitPrice"/>

<property name="pkgPrice" column="pkgPrice"/>

<many-to-one name="minimalOrderUnit" column="minimalOrderUnit" class="com.fivestaroffice.databeans.OrderUnit"/>

<property name="minimalOrderAmt" column="minimalOrderAmt"/>

</class>

</hibernate-mapping>

public class Product {

...

private Category parentCate;

public void setParentCate(Category parentCate) {

this.parentCate = parentCate;

}

public Category getParentCate() {

return parentCate;

}

...

}

I'm trying to retrieve all product records from the DB in a controller. All product objects are created, but their parentCate (type Category) are all null.

When I save products into the DB, I simply set the products' parentCate through the Product bean's setter, and Category id's are all correctly saved.

Why I can't get them out?

[2047 byte] By [max1983a] at [2007-10-3 8:50:05]
# 1
try a hibernate forum
MickeyOnJavaa at 2007-7-15 3:59:28 > top of Java-index,Other Topics,Patterns & OO Design...