Hi,
I have following situation:
Parent table:
ID - PK
NAME
MAIN_CHILD_ID - FK (has FK constraint) and can be null
Child table:
ID - PK
NAME
PARENT_ID - FK (has fk constraint) and not null
Mapping for this looks like:
<class name="test.Parent" table="PARENT">
<id name="id" column="ID">
<generator class="sequence">
<param name="sequence">PARENT_S</param>
</generator>
</id>
<property name="name" column="NAME" type="string"/>
<set name="children" inverse="true" lazy="true" outer-join="true"
cascade="all-delete-orphan">
<key column="PARENT_ID"/>
<one-to-many class="test.Child"/>
</set>
<many-to-one name="mainChild" class="test.Child" column="MAIN_CHILD_ID"
cascade="all"/>
</class>
class name="test.Child" table="CHILD">
<id name="id" column="ID">
<generator class="sequence">
<param name="sequence">CHILD_S</param>
</generator>
</id>
<property name="name" column="NAME" type="string"/>
<many-to-one name="parent" class="test.Parent" column="PARENT_ID"
not-null="true"/>
</class>
For mainChild association I'm using many-to-one and it causes problem because of
cascade order. It tries to create mainChild before parent is created. I have tried to
use one-to-one which in this case more suitable because mainChild is one-to-one
association but in one-to-one there is no column property to specify foreign key to
use for association resolution it assumes that primary key is used for that.
I saw that hibernate always cascades many-to-one before parent is created. Is there is
any way how to custmoize casading order in many-to-one ? or specify foreign key column
in one-to-one ?
PS: it's possible to workaround this situation by creating Parent first with mainChild
null and later create main child and set that to the parent in the same transaction.
Thanks,
Giedrius
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
hibernate-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/hibernate-devel