• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

How to make a JOIN without a directly mapped entity?

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi people!

If I have for example two entities, Client and Product, in product entity I have a relationship with client, so I have a @ManyToOne JPA relationship.

Client

Product
- client_id

But I wonder to make an "inverse" JOIN (left) query, because its possible under native SQL using <type> JOIN ON Table (id1 = id2), but how to figure out some situation under JPA?

If I heading doing something like that I got an error:



Because 'ON' clause is not allowed up there, I know that I can use other maner like:



But sometimes I have to use like an native SQL, to JOIN a entity that don´t have directly link. Sorry If I was not clean in my ideas.

Regards!
 
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you might want to do something like

Select p.*, (Select c.<column> from Client c where c.id = p.id ) from Product p.

It will give the same result as when the join is Left Outer done from Product to Client..
 
Inocencio Oliveira
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Rahul, I will try this way soon and repley back here.
 
Inocencio Oliveira
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did it, but I have some questions.

how can I test some conditions about client, like:



Thanks again!
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like this...
 
For my next trick, I'll need the help of a tiny ad ...
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic