aspose file tools*
The moose likes Object Relational Mapping and the fly likes Can I join two tables in a NamedQuery? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Can I join two tables in a NamedQuery?" Watch "Can I join two tables in a NamedQuery?" New topic
Author

Can I join two tables in a NamedQuery?

Sheetal Tiwari
Greenhorn

Joined: May 12, 2009
Posts: 18
Hello,

I have two 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.
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.


SCJP
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

you should be dealing with objects, not tables hence you would have
select person p where
p.address.country='Oz'
Sheetal Tiwari
Greenhorn

Joined: May 12, 2009
Posts: 18
For example can I write a NamedQuery for the following SQL?

"Select * from A, B
Where A.id = B.id
order by B.sortOrder"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I join two tables in a NamedQuery?