Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » OneToMany with composite keys(Problems creating OneToMany relationship for tables with composite keys)
OneToMany with composite keys [message #882911] Thu, 07 June 2012 13:10 Go to next message
Jakob Nordstrom is currently offline Jakob NordstromFriend
Messages: 1
Registered: June 2012
Junior Member
Hi,

Using EclipseLink 2.3.2. Db is HSQLDB (for testing). I'm trying model part of a legacy data base schema, which I cannot change. There is one particular relationship which I have not been able to create:

There is a conceptual one-to-many relationship between TableA and TableB:

TableA
id (pk)
sequence (pk)
tableBid (fk)

TableB
id (pk)
sequence(pk)
value

So TableA references half of TableB's composite primary key. I suppose it could be argued that this is a many-to-many relationship since there is no guarantee that the same row in table B will not be referenced by several rows in table A. Would I have to model this as a many-to-many and create a link table or is there any other way of molelling this?
Re: OneToMany with composite keys [message #885157 is a reply to message #882911] Tue, 12 June 2012 14:43 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

If the id in B is unique, then you could just make it the Id in your entity and ignore the sequence as the id.

If it is not unique, then this is an odd relationship, you could model it using a selectionCriteria on the mapping, or using a DescriptorCustomizer to just set the one foreign key (instead of the two that get defaulted).

See,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/MappingSelectionCriteria


James : Wiki : Book : Blog : Twitter
Previous Topic:MOXy jaxb binding error for redefine element
Next Topic:Understanding internals
Goto Forum:
  


Current Time: Tue Dec 23 02:33:57 GMT 2014

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

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