[jboss-user] [EJB 3.0] - Re: Etity reference problems

fhh do-not-reply at jboss.com
Mon Apr 2 18:32:07 EDT 2007


Two things:


  | public class C {
  | 
  |    @Id
  |    @Column(name = "Aid")
  |    private Integer id;
  | 
  |    @OneToOne
  |    @JoinColumn(name = "Aid", nullable=false)
  |    private A a;
  | 
  |    @OneToOne
  |    @PrimaryKeyJoinColumn
  |    private B b;
  | 
  |    ...
  | }
  | 

- This doesn't look good to me. You are mapping the column "Aid" twice.
- If the tuple(a,b) is unique use an @EmbeddedId.

2.) Do you need Class C at all? Simply use a @JoinTable:


 
  | public class A {
  | 
  |    @Id
  |    @GeneratedValue(strategy = GenerationType.IDENTITY)
  |    @Column(name = "Aid")
  |    private Integer id;
  | 
  |    @OneToMany(cascade = CascadeType.ALL, mappedBy = "A", fetch = FetchType.LAZY)
  |    private List<B> Bs = new ArrayList<B>();
  | 
  | 
  |    @OneToOne
  |    @JoinTable(name="C",
  |     joinColumns=@JoinColumn(name="Aid"),
  |     inverseJoinColumns=@JoinColumn(name="Bid")
  |    private B b = null;
  | 
  |    ...
  | }
  | 

This will only work if C has some more properties. (And I have never tried a @OneToOne-Relationship using a JoinTable before. YMMV).

Regards

Felix

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

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



More information about the jboss-user mailing list