Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA table JOIN

 
Sheetal Tiwari
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have two entities/tables that have one to one relationship and I have created java classes for both of them and annotated with @Entity.
Now for a particular case, I want to join both these tables and fetch the data.

For Example
SELECT * from A,B
where A.id = B.id
order by B.sortOrder

Can tables be joined in @NamedQuery ?
Is yes , could you provide a sample.

If it cannot be done using @namedQuery then is it advisable to use @NamedNativeQuery in this scenario.

Thanks for the help.
 
Pierre Sugar
Ranch Hand
Posts: 62
Java Ruby Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might find this site helpfull. There is an example that would answer your question:


But I am wondering as you have an association to class B I think you could also use this NamedQuery (I didn't try it though).


b in the NamedQuery is the field name of class B in your A class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic