Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » How can I associate primary and secondary tables with a join criteria other than the compound key
How can I associate primary and secondary tables with a join criteria other than the compound key [message #624561] Wed, 22 September 2010 05:26 Go to next message
Rich Mayfield is currently offline Rich MayfieldFriend
Messages: 44
Registered: August 2010
I am trying to essentially implement an entity on top of a join of two tables but am finding the binding of primary keys and table join criteria to be prohibitive.

My entity has a compound key of "columnA" and "columnB" - basically each field is annotated with @Id, both of which come from my primary table (t0).

The main table has most everything and the secondary table has one additional piece of information - call it "columnC" in this secondary table (t1)

I want the join criteria to be simply:

t0.columnA = t1.columnA

but I want the compound key of the entity to be {t0.columnA, t0.columnB). t1 does not have a columnB equivalent - yep, I want a full join.

When I use a @SecondaryTable I need to specify the primary key that links the two tables together. In this case it is just "columnA" to "columnA".

EclipseLink gives me the error:

An incomplete @PrimaryKeyJoinColumns was specified on the annotated element [class xxx]. When specifying @PrimaryKeyJoinColumns for an entity that has a composite primary key, a @PrimaryKeyJoinColumn must be specified for each primary key join column using the @PrimaryKeyJoinColumns. Both the name and the referencedColumnName elements must be specified in each such @PrimaryKeyJoinColumn.

It looks like there's a strong linkage between the primary key for associating tables (in a join) and the entity's "id". How can I get around this?
Re: How can I associate primary and secondary tables with a join criteria other than the compound ke [message #628626 is a reply to message #624561] Thu, 23 September 2010 13:32 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1294
Registered: July 2009
Senior Member

I'm not sure I follow the table design here. Does columnA uniquely identify rows in both tables? If so, why use the compound pk fields and not just use the columnA as the Id? If it is not unique, it implies that Table2 has a 1:M relationship to rows in Table1. This will cause problems on inserts, as using a secondary table annotation relies on there being a 1:1 relationship - it will cause duplicate inserts to Table2 when a non-unique columnA is used.

If columnA is not unique, I would recommend mapping the second table as its own entity and using a 1:1 relationship from the first, allowing the entity to be shared. If it is unique, you can mark columnA as the primary key, or if you still wish to use a composite pk for the table, map the secondary table using native EclipseLInk api in a customizer using the descriptor addTable and addForeignKeyFieldNameForMultipleTable methods:

descriptor.descriptor.addForeignKeyFieldNameForMultipleTable ( "TABLE1.COLUMNA", "TABLE2.COLUMNA");

Best Regards,
Previous Topic:PrivateOwned dont work in Embeddable class
Next Topic:Problems to use order by a null association
Goto Forum:

Current Time: Sun Apr 22 08:28:11 GMT 2018

Powered by FUDForum. Page generated in 0.02016 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software