• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make a JOIN without a directly mapped entity?

 
Inocencio Oliveira
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • 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!
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Like this...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic