Heres a brief explanation of the scenario:
I like to create a Question-Catalogue, therefore I need a "Question". So I modelled a Class QUESTION. A QUESTION can have a link to another QUESTION, so a Question-Object actually might hold a reference to another Question-Object.
Here is the Java-Code:
Code:
public class Question {
private String id;
private String text;
private Question linkedQuestion;
//Constructor
...
//Methods: getters and setters
...
}
And this is what my mapping does look like:
Code:
<class name="Question"
table="QUESTIONS"
<id name="id" column="ID">
<generator class="uuid.string" />
</id>
<property name="text" column="TEXT" />
<many-to-one name="linkedQuestion" column="LINKED_QUESTION_ID"
class="Question"
cascade="save-update" />
</class>
Now I do the following:
Code:
Question q = new Question();
q.setText("I am doing something wrong?");
Question linkedQ = new (Question);
linkedQ.setText("Do I need help?");
q.setLinkedQuestion(linkedQ);
So far, so good. When I save "q", "linkedQ" is also persistet and the table QUESTIONS has two new rows, so everything seems to work quite nice.
But when I want to delete a question it only works if I first delete "q" and then "linkedQ". If I try to delete "linkedQ", an SQLException is thrown, saying I am violating an integrity constraint.
I somehow have the feeling, that the answer is way simple... but although I read the manual and searched the forum more than a dozen times, I haven't found a solution yet :-(
Best thanks in advance for any answers
Philipp Hinnah