1

As per hibernate documentation:

To map a bidirectional one to many, with the one-to-many side as the owning side, you have to remove the mappedBy element and set the many to one @JoinColumn as insertable and updatable to false. This solution is not optimized and will produce some additional UPDATE statements.

@Entity  
public class Troop {  
    @OneToMany  
    @JoinColumn(name="troop_fk") //we need to duplicate the physical information  
    public Set<Soldier> getSoldiers() {  
    ...  
}  

@Entity  
public class Soldier {  
    @ManyToOne  
    @JoinColumn(name="troop_fk", insertable=false, updatable=false)  
    public Troop getTroop() {  
    ...  
}  

My questions are:

  1. What is the advantage of such a setup. Why not create Manytonone side as the owning side
  2. Why in this setup these two values are needed: insertable=false, updatable=false
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
sab
  • 9,767
  • 13
  • 44
  • 51
  • I think you're missing the point of that quote from the documentation. It's not recommending you use one side or the other as the owning side, just describing how to set up a specific one. – Matt Ball Sep 13 '10 at 13:43
  • Thanks. But I understand that point. My question really is what is the purpose of setting this up this way rather than many to one setup – sab Sep 13 '10 at 14:04

0 Answers0