I would like to evaluate JPA in an existing project. The database model and Java classes exist and are currently mapped using self-generated code. The database model and Java classes do not fit together perfectly, but custom mapping works well. Nevertheless, using JPA in general seems worthwhile to try.
As you can see, I am new to JPA and have to do work with the xml configuration. I am currently working on one-to-many one-way relationships using a connection table (please do not discuss this scenario here).
A (one - relationship owner) <-> AB (JoinTable) <-> B (many)
The tables look like this:
A
--
ID
BREF
...
B
--
ID
...
AB
--
A_BREF (foreign key to a reference column in A which is NOT the id)
B_ID
I would like to define a one-to-many one-way relationship for class A.
class A {
private List<B> bs;
}
and did it as follows:
<one-to-many name="bs">
<join-table name="ab">
<join-column name="a_bref">
<referenced-column-name name="bref" />
</join-column>
<inverse-join-column name="b_id">
<referenced-column-name name="id" />
</inverse-join-column>
</join-table>
</one-to-many>
Althoug, , . , A. "B" A.ID A.BREF .
() ( eclipselink 2.2.0)?
!
EDIT:
, @SJuan76,
<one-to-many name="bs">
<join-table name="ab">
<join-column name="a_bref" referenced-column-name="bref" />
<inverse-join-column name="b_id" referenced-column-name="id" />
</join-table>
</one-to-many>
( eclipselink 2.1.0 2.2.0)
eclipselink 2.1.0
: name [bref] , .
eclipselink 2.2.0
: [bref], [field bs] .
, referenced-column-name="bref" , referenced-column-name="id" inverse-join-column. , referenced-column-name. , . ?
:
szenario , BREF,
class A {
private long bref;
private List<B> bs;
}
orm.xml
<basic name="bref">
<column name="bref" />
</basic>
, referenced-column-name - ( name join-column/inverse- join-column, .)
. , ( ) . , , .
+1 !