Hello,
I've got the following table structure from an existing project which is running with EJB2.0 Entities. I'm migrating those entities to EJB3.0 JPA Objects. However, I'm faced to the following problem :
I've got a OneToOne bidirectionnal association between class A and class B. The fact is that the database table is made like
this : table A(col_A_ID, col_A_1, col_A_2, col_B_ID) table B(col_B_ID, col_B_1, col_B_2, col_A_ID)
We've got a primary key for table A (col_A_ID) and a primary key for table B (col_B_ID) We've got a foreign key for table A (col_B_ID) and a foreign key for table B (col_A_ID)
I've sawn samples for Hibernate with only one side of the relation mapping the foreign key, but never both sides.
The following code emphasis the fact that Table A.col_B_ID is missing, there will be only Table B.col_A_ID : --- public class A { ... @OneToOne(mappedBy="a") private B b; ... } --- public class B { ... @OneToOne @JoinColumn(name="col_A_ID") private A a; ... } ---
Is it possible to manage to do OneToOne bidir with 2 foreign keys (one for each side) with JPA & Hibernate ? Why is it not
done by default as with EJB2.0 ? If it is possible to still do such a thing, is it much more costly concerning the
performances of the application ?
Regards, Blured.
|