I was thinking before posting some code to get an answer if the comportament that I've got from Hibernate is an usual one or it is an error.
Here is my configuration:
I use Hibernate 2.1.2, Oracle 8.1.7
the parent object is of type Societe :
<class
name="Societe"
table="SOCIETE"
>
<id
name="id"
type="long"
column="ID"
unsaved-value="0"
>
<generator class="seqhilo">
<param name="sequence">SOCIETE_SEQ</param>
<param name="max_lo">100</param>
</generator>
</id>
<property
name="nom"
type="java.lang.String"
column="NOM"
not-null="true"
unique="true"
length="60"
/>
<!-- bi-directional one-to-many association to AdresseSociete -->
<set
name="adresseSocietes"
lazy="true"
inverse="true"
cascade="all"
>
<key>
<column name="SOC_ID" />
</key>
<one-to-many
class="AdresseSociete"
/>
</set>
</class>
and the collection is of type AdresseSociete:
<class
name="AdresseSociete"
table="ADRESSE_SOCIETE"
>
<id
name="id"
type="long"
column="ID"
unsaved-value="0"
>
<generator class="seqhilo">
<param name="sequence">ADRESSE_SOCIETE_SEQ</param>
<param name="max_lo">100</param>
</generator>
</id>
<property
name="adresse"
type="java.lang.String"
column="ADRESSE"
length="255"
/>
</class>
The execution order is:
I charge in the Hibernate session an Societe object
Hibernate session is closed
I send the Societe object to a different tier. Here I don't copy the AdresseSociete collection because I dont't need it.
I change in the UI tier the name of the Societe.
Then in a newly created session, in the persistence tier I save and commit the Societe object.
I charge the Societe object with Session.load(id, class)
If I try to acced to the adresseSocetes collection it returns me a null collection. Is this normal?
How ever if I make an session.clear() before loading and after the save of the Societe object the adresseSocetes collection is well initialized
Thanks
|