Hello everybody,
This is my first attempt at using hibernate (3.2) and I am running into an issue with many-to-many associations. I have a desktop application and its interaction to the database only happens when the user saves and exits or loads from the database when the application is booted up. There is no retrieving/saving of data on a page-by-page basis.
Now I have a StatementOfOrder object which contains lines of AccountingItems, and an AccountingItem can be contained in multiple StatementOfOrders. My hibernate mapping for the StatementOfOrder table looks like this--
Code:
<list name="accountingItems" table="SOO_ITEMS" lazy="false" cascade="save-update">
<key column="SOO_ID"/>
<index column="INDEX"/>
<many-to-many
column="ITEM_ID"
class="AccountingItem"
fetch="join"/>
</list>
When the user saves their data, exits the application, and then loads the data on application startup, the list of accountingItems does not get populated (or I hear the other term 'hydrated'). The StatementOfOrder object gets 'hydrated' appropriately--I can see its UUID--but when I iterate over the list of AccountItems, they return the appropriate items in order but are not populated (no UUIDs set).
I tried adding the attribute 'fetch="join"' to the
list element but get some kind of lazy initialization exception. I retrieve the StatementOfOrder object from the database like this--
Code:
StatementOfOrder soo = (StatementOfOrder)query.uniqueResult();
So how can I force hibernate to hydrate my list of AccountItems when the user loads data from the database?