Hi,
i am new to hibernate and want to config the following ont-to-one relation (it's an extract, not the real model):
Code:
----------------- ----------------
| TASK | | TASKRESULT |
----------------- 1 0..1 ----------------
| id | <----------------> | id |
----------------- ----------------
| action | | result |
----------------- ----------------
- I like to navigate the relation from the TASK to the TASKRESULT. The reverse direction is not required.
- I like to get TASKRESULT.id assigned the same value as TASK.id.
- I like to get TASKRESULT deleted automatically when TASK is deleted.
i tried the following mapping:
Code:
- TASK -
==========
<class name="Task" table="task">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="action" column="action"/>
<one-to-one name="result" type="TaskResult" cascade="save-update,delete"/>
</class>
- TASKRESULT -
==============
<class name="TaskResult" table="taskresult">
<id name="id" column="id">
<generator class="foreign">
<param name="property">task</param>
</generator>
</id>
<one-to-one name="task" type="Task" constrained="true"/>
</class>
Now i observe the following problems:
1.) When i try to delete a TASK, associated with a TASKRESULT, i get a integrity constraint violation, because TASKRESULT.id is a FOREIGN KEY of TASK.id. How do i tell hibernate to delete the TASKRESULT before deleting TASK?
2.) I do not want to navigate from TASKRESULT to TASK. So how do i have to config TASKRESULT to get the TASKRESULT.id assigned with the same value as TASK.id but without the need to declare a property task in the class TaskResult?
Thx for any suggestions, i am a bit clueless. I did study the documentation and the web for more than 4 hours now.
Thx and best regards,
JDon