aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate Inner Join with AND criteria Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Inner Join with AND criteria " Watch "Hibernate Inner Join with AND criteria " New topic
Author

Hibernate Inner Join with AND criteria

Ram Mandavkar
Greenhorn

Joined: Mar 23, 2009
Posts: 16
Hello All,

SQL :
SELECT p.id, p.name, s.id, s.name, c.name from Product As p inner join supplier as s On p.supplierid =s. supplierid and s. compayid=1 inner join customer as c on p.customerid=c.customerid and c. compayid=1

I do not want to use where close in above SQL

HQL (Working):
SELECT p.id, p.name, s.id, s.name, c.name from Product p inner join p.supplier as s inner join p.customer as c

I had tried

SELECT p.id, p.name, s.id, s.name, c.name from Product p inner join p.supplier as s and s. compayid=1 inner join p.customer as c and c. compayid =1

But Exception “unexpected token: and”

Can anyone help me to add ‘and s.compayid =1’ clause in above HQL to get it work.

Regards
Ram Mandavkar
Victor Dolirio
Ranch Hand

Joined: Aug 21, 2008
Posts: 57
Have you already tried to use the "with" keyword? I'm not sure if this keyword might work cause I never had used it in inner joins. Try somethink like the folowing as a matter of taste...



If happen something bad in you life, don't ask God why it happened. Ask for what.
SCJP 5 (80%) - SCWCD 5 (91%) - SCBCD & SCJD coming soon...
Ram Mandavkar
Greenhorn

Joined: Mar 23, 2009
Posts: 16
Hello Victor,

Thanks for suggestion
I was using Hibernate 3.0 which is not supported 'WITH' KEYWORD

as per Hibernate 3.1.3 Released
http://www.roseindia.net/hibernate/hibernate3.1.3.shtml
** Improvement
* [HHH-1520] - with clause with implied joins within an explicit join

It works with Hibernate 3.1.3

I had changed Hibernate 3.0 with Hibernate 3.1.3
and it works

Thanks again


 
jQuery in Action, 2nd edition
 
subject: Hibernate Inner Join with AND criteria