Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Inner Join with AND criteria

 
Ram Mandavkar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

 
Ram Mandavkar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic