Hello,
I am trying to use hibernate to migrate data between two databases. The approach I was thinking was basically to have a hbm.xml mapping file to map the source data to a POJO, within the context of a "source" database hibernate session, then use the same POJO to map to a different hbm.xml file associated with a "destination" database hibernate session.
Based on documentation and reading through some forum posts, it sounds like I would want to do a procedure like:
1. start new "source" hibernate session
2. load the rows for a database table into a collection (my dataset is small)
3. close the hibernate session, so that the objects become "detached"
4. start a new "destination" hibernate session, start transaction
5. save the items from the collection ("session.save(eachItem)"). (I know there are facilities for batch saving items, but i want to get it working first, and then worry about optimizing.)
6. commit transaction
One of the objects has a <list> of children. On both the "source" and "destination" hbm.xml, it is configured as such (names generalized for simplicity):
Code:
<list name="items" table="items" lazy="false" cascade="all">
<key column="parentid" not-null="true" />
<list-index column="index" />
<composite-element class="foo.bar.Parent$Item">
<property name="amount" column="amount" type="long" />
<type name="org.hibernate.type.EnumType">
<param name="enumClass">foo.bar.ItemType</param>
<param name="type">12</param>
</type>
</property>
<property name="period" column="period">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">foo.bar.ItemPeriod</param>
<param name="type">12</param>
</type>
</property>
</composite-element>
</list>
(There are other parts of the hbm.xml files where other parts of the mapping differ, which is why I am not using the same file on both sides.)
What is happening is that the <list> of items is not getting saved to the destination database.
Could someone be so kind as to point out what I am doing wrong? Perhaps my approach is not optimal?
Cheers,
Alex