Hi,
i'm having some problems with my annotation based Hibernate mapping. Inserting and deleting data works great. But when I update Table1 (
Question) a malicious update on Table2 (
Answer) gets automatically invoked. There is a
bidirectional One-To-Many relation between Question and Answer.
Quote:
Hibernate: update PUBLIC.question set [...] where question_id=?
Hibernate: update PUBLIC.answer set question_id=null where question_id=?
I don't know why Hibernate is updating the
answer-table, since the
question_id is never changed actually. I could not find any reason for this behaviour. I tried various approaches of annotations, e.g. different values for @JoinColumn settings "nullable", "updatable", "insertable". This is basically the current entity composition:
Question.java
Code:
@Entity
@Table(name = "question")
public class Question extends ContainsPicture implements Comparable<Question> {
@Id
@GeneratedValue
@Column(name = "question_id", updatable = false)
private Long id;
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "question_id")
private Set<Answer> answers = new HashSet<Answer>();
[...]
}
Answer.java
Code:
@Entity
@Table(name="answer")
public class Answer extends ContainsPicture implements Comparable<Answer> {
@Id
@GeneratedValue
@Column(name="answer_id", updatable = false)
private Long id;
@ManyToOne
@JoinColumn(name="question_id")
private Question question;
[...]
}
Has anyone an idea of how to fix this? Or can someone tell me what i'm doing wrong? Any help would be appreciated.
Thanks,
Alex