Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » @ManyToOne relation problem
@ManyToOne relation problem [message #387082] Fri, 10 April 2009 10:30 Go to next message
Somebody Somebody is currently offline Somebody Somebody
Messages: 2
Registered: July 2009
Junior Member
Hi,

I have a dilemma:

+ I have 2 entities with a ManyToOne relationship and no unique ids
(Embedded ids):

Entity A (date, field1, field2)
Entity B (field1, field2, startDate, endDate)

+ Primary key of Entity B is an embedded id composed by field1, field2,
and startDate.

+ Relationship between EntityA and EntityB

SELECT EntityB.*
FROM EntityA, EntityB
WHERE EntityB.field1 = EntityA.field1
AND EntityB.field2 = EntityA.field2
AND EntityB.startDate <= EntityA.date
AND EntityB.endDate > EntityA.date

It always return an unique row.

=> Is it possible to establish the relationship between EntityA and Entity B
with JPA annotations to fetch EntityA rows or I need to use a JPQL query to
make the join ?
Re: @ManyToOne relation problem [message #387088 is a reply to message #387082] Tue, 14 April 2009 04:15 Go to previous messageGo to next message
Somebody Somebody is currently offline Somebody Somebody
Messages: 2
Registered: July 2009
Junior Member
Any idea ?
Re: @ManyToOne relation problem [message #387094 is a reply to message #387082] Wed, 15 April 2009 09:32 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

JPA only allows relationships to be define using foreign keys
(JoinColumn). However in EclipseLink you can define complex relationships
such as this using the Expression criteria API and a DescriptorCustomizer.

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

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Previous Topic:multiple xml-mappings from fragments?
Next Topic:@Version field does partially update?
Goto Forum:
  


Current Time: Sat Aug 30 02:37:55 EDT 2014

Powered by FUDForum. Page generated in 0.01961 seconds