Does hibernate have and order on how mappings/relations between entities are made persistant in the data base. Take the example xml mapping I've written below:
Code:
<class name="Foo" table="FooTable">
<id name="id" column="Foo_Id">
<generator class="native" />
</id>
<property name="repr" type="text" />
<many-to-one name="bar_object" column="BarObjectClass_ID" />
<list name="values" table="ValuesOfOtherObjectTypeInFoo">
<key column="Foo_Id" not-null="true"/>
<list-index column="sortedOrder" />
<many-to-many column="OtherObjectType_ID" unique="true" class="OtherObjectType"/>
</list>
</class>
An instance of the Foo class is mapped many-to-one with some BarObject instance and is also mapped many-to-many (actully a join many-to-one) with another class. The problem I've is that BarObject set restrictions on the instance of Foo, in particular a Foo instance it's going to be related with "OtherObjectType" if the restrictions on BarObject are met. So when saving a Foo instance I
first need to set the relation with "BarObjectClass" and
then relate it with "OtherObjectType".
When I first tried this The mapping was like this:
Code:
<class name="Foo" table="FooTable">
<id name="id" column="Foo_Id">
<generator class="native" />
</id>
<property name="repr" type="text" />
<list name="values" table="ValuesOfOtherObjectTypeInFoo">
<key column="Foo_Id" not-null="true"/>
<list-index column="sortedOrder" />
<many-to-many column="OtherObjectType_ID" unique="true" class="OtherObjectType"/>
<many-to-one name="bar_object" column="BarObjectClass_ID" />
</list>
</class>
An instance the property "repr" has different values depending on the values list.
Repr is generated when the .getRepr() is called depending on the values list and the values list depends on the association <many-to-one name="bar_object" column="BarObjectClass_ID" />. I get wrong results with the above mapping. Although the first mapping I showed you gives the correct results, and I would like to know if this is not just a "coincidence".
I've scanned through most documantation I could get a hang on, If I missed something, please inform me!
Thanks in advance.
Ale.