-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Updating Table1 invokes Updating FK=NULL on Table2
PostPosted: Fri Aug 26, 2011 11:00 am 
Newbie

Joined: Fri Aug 26, 2011 10:23 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.