[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Re: Two Entity has @OneToMany to the same Entity

claudio_br do-not-reply at jboss.com
Wed Dec 12 11:33:14 EST 2007


You can resolve this with:

@Entity
  | public class A implements Serializable{
  | 
  |   @Id
  |   @GeneratedValue(strategy = GenerationType.IDENTITY)
  |   @Column(name="id_a")
  |   private int id;
  | 
  |   @OneToMany(mappedBy="a", fetch = FetchType.EAGER)
  |   @Cascade(CascadeType.ALL)
  |   private Set<C> cs = new HashSet<C>();
  |   
  |   .
  |   .
  |   .
  | 
  | }
  | 
  | @Entity
  | public class B implements Serializable{
  | 
  |   @Id
  |   @GeneratedValue(strategy = GenerationType.IDENTITY)
  |   @Column(name="id_b")
  |   private int id;
  | 
  |   @OneToMany(mappedBy="b", fetch = FetchType.EAGER)
  |   @Cascade(CascadeType.ALL)
  |   private Set<C> cs = new HashSet<C>();
  |   
  |   .
  |   .
  |   .
  | 
  | }
  | 
  | @Entity
  | public class C implements Serializable{
  | 	
  |   @ManyToOne(fetch = FetchType.EAGER)
  |   @JoinColumn(name="id_a", insertable=true, updatable=true)
  |   @Fetch(FetchMode.JOIN)
  |   @Cascade(CascadeType.SAVE_UPDATE)
  |   private A a;
  | 	
  |   @ManyToOne(fetch = FetchType.EAGER)
  |   @JoinColumn(name="id_b", insertable=true, updatable=true)
  |   @Fetch(FetchMode.JOIN)
  |   @Cascade(CascadeType.SAVE_UPDATE)
  |   private B b;
  | 	
  |   .
  |   .
  |   .
  | }

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4112298#4112298

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4112298



More information about the jboss-user mailing list