Hi
i try to use the new XML feature to export data stored within my database to be able to import this data in a other database (customer database). I want to do this to provide some initial data needed for my application. However this works fine, if i have only flat tables without any associations. But i recogized problems if i have hierarchical data structures. For example i have user groups within my system and user groups may be subgroups of other user groups.
eg: the structure looks like the following
group 1 (uid=1)
---> group 1.1 (uid=2)
--------> group 1.1.1 (uid=3)
---> group 1.2 (uid=4)
etc.
In this case i export the data the following format using EntityMode.DOM4J. Due to the hierarchical structure, the many to one association between groups and subgroups are not embeded within the parent element (embed-xml=false):
Code:
<group uid = "1">
<name>group 1</name>
</group>
<group uid = "2">
<name>group 1.1</name>
<parentgroup uid = "1"/>
</group>
<group uid = "3">
<name>group 1.1.1</name>
<parentgroup uid = "2"/>
</group>
<group uid = "4">
<name>group 1</name>
<parentgroup uid = "1"/>
<group>
If i try to replicate the data from XML into a empty database the group with uid = 1 will be replicated first. Then the group with uid = 2 should be replicated and so on. But this does not work, because the first group gets a new identifier value. This identifier value can be different from the identifier value assigned within the source database because it is not garanteed, that the same identifier will be assigned by the destination database too. In this case the foreign key constraint (parentGroup) for the group with uid = 2 does not hold and a ConstraintViolatedException is thrown by the jdbc driver.
According to the hibernate documentation which says (section 11.9):
Quote:
It is occasionally useful to be able to take a graph of persistent instances and make them persistent in a different datastore, without regenerating identifier values.
it should be no problem because the identifier values are reused, but this does not hold for my experiments, when i am trying to replicate the data in a total empty database.
Does anybody has similar problems and does anybody know how to solve this problem?
i would be very glad if somebody can take me out of the dark ;-)
kind regards
Markus