Hi,
I have 2 tables: customer and house. One customer can have multiple houses. For this reason in the table house I inserted a foreign key customer_id which maps to customer.id field.
In my hibernate mapping file I have:
for Customer
Code:
<class name="Customer" table="customer">
<id column="id" name="id" type="int" unsaved-value="0">
<generator class="increment"/>
</id>
<property column="name" generated="never" lazy="false"
name="name" type="java.lang.String"/>
...
<list name="houses" inverse="true" lazy="false" cascade="all">
<key column="customer_id" not-null="true" />
<index column="id" />
<one-to-many class="House"/>
</list>
</class>
for House:
Code:
<class name="House" table="house">
<id column="id" name="id" type="java.lang.Integer" unsaved-value="0">
<generator class="increment"/>
</id>
<property column="street" generated="never" lazy="false" name="street" type="java.lang.String"/>
...
<many-to-one class="Customer" fetch="select" name="customer" lazy="false">
<column name="customer_id" not-null="true"/>
</many-to-one>
</class>
In the Customer POJO class I have inserted a property:
Code:
private List<House> houses = new ArrayList <House>(0);
The problem is that my DAO object returns a houses list with many empty elements.
For example the house id=7 is the only house for a customer. DAO returns the list with 7 elements, the first 6 are empty and the last one has the right House object.
Maybe someone had already a similar problem and can give me a tip.
Thank you