Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Left outer join on a unidirectional many to one mapping
Left outer join on a unidirectional many to one mapping [message #518116] Wed, 03 March 2010 07:08 Go to next message
Andreas Christoforides is currently offline Andreas ChristoforidesFriend
Messages: 6
Registered: July 2009
Junior Member
I have a many to one relationship from object A to object B.

When I use a bidirectional mapping I can executed the following JPQL query:

SELECT b, a FROM B b LEFT OUTER JOIN b.a a


How can I achieve the same result if I have a unidirectional mapping?

I know it can be done in SQL but I would like to implement it in JPQL.

Thanks,
Andreas
Re: Left outer join on a unidirectional many to one mapping [message #518587 is a reply to message #518116] Thu, 04 March 2010 14:56 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Maybe,

"Select b, a from A a left join a.b b"

or,
"Select b, a from B b, A a where a.b = b"


James : Wiki : Book : Blog : Twitter
Re: Left outer join on a unidirectional many to one mapping [message #519188 is a reply to message #518587] Sun, 07 March 2010 21:07 Go to previous messageGo to next message
Andreas Christoforides is currently offline Andreas ChristoforidesFriend
Messages: 6
Registered: July 2009
Junior Member
The first query is the opposite of what I want. It will give all rows of A and information from B if the relationship is set.

The second query does the same thing but with a different notation.

Would it help if I posted my actual mappings and query?
Re: Left outer join on a unidirectional many to one mapping [message #519191 is a reply to message #518116] Sun, 07 March 2010 21:52 Go to previous messageGo to next message
Andreas Christoforides is currently offline Andreas ChristoforidesFriend
Messages: 6
Registered: July 2009
Junior Member
Here is the outer join I want to perform in native SQL:

SELECT a.*, b* FROM A a LEFT OUTER JOIN B b ON (b.aID = a.ID);
Re: Left outer join on a unidirectional many to one mapping [message #519383 is a reply to message #518116] Mon, 08 March 2010 16:52 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

That is what,

"Select b, a from A a left join a.b b"

would generate? I assume you want "B b LEFT OUTER JOIN A a" though.

I guess there is no way to do this in JPA without adding the bidirectional relationship, or using native SQL.

In EclipseLink, you can add a OneToOneQueryKey that allows you to define a relationship without having a mapping for it. You can then use the query key in EclipseLink Expression queries. Unfortunately, query keys are not currently supported in JPQL queries (please log a bug for this and vote for it).


James : Wiki : Book : Blog : Twitter
Previous Topic:Database Locks after upgrading from Toplink to Eclipselink
Next Topic:JPA 2 metamodel generator with Maven
Goto Forum:
  


Current Time: Tue Mar 19 04:08:30 GMT 2024

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

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

Back to the top