Quote:
There is another problem when I use merge(). I lose the associations when I merge() the object.
I guess that is because you have not explicitly asked to cascade the relationships during a merge/save-update operations.
include cascade="merge, save-update" in <set> collections in your mapping file.
i.e.,
Code:
<set name="companies" inverse="true" cascade="merge, save-update">
<key>
<column name="userId" />
</key>
<one-to-many class="lacarte.persistence.Company" />
</set>
<set name="transactions" inverse="true" cascade="merge,save-update">
<key>
<column name="userId" />
</key>
<one-to-many class="lacarte.persistence.Transaction" />
</set>