1

In my project (java struts 2, hibernate), I want to select with join between 2 table.

Class User {
  private int userId;
  private String userName;
  private String dateOfBirth;
}

Class Bill {
  private int billId;
  private String dateOfBill;
  private Double moneyOfBill;
  private User user;
}

It is OK when I tried via sql in localhost DB directly

Select * From user u JOIN bill b ON (b.userId=u.userId) Group by b.userId Order by Sum(b.moneyOfBill) asc;

But it is error in my program via hibernate hql

From User U JOIN Bill B ON (B.user.userId=U.userId) Group by B.user.userId Order by Sum(B.moneyOfBill) ASC;

The error in eclipse console:

at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54) at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47) at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82) at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:281) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:180) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134) at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:101) at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:80) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1650)

Please help. Thank you!

Saharsh Shah
  • 28,687
  • 8
  • 48
  • 83
Bentley
  • 143
  • 10
  • This solution fixes my problem: http://stackoverflow.com/questions/16354705/hql-join-path-expected-for-join-hibernate – Bentley Nov 28 '14 at 07:30

1 Answers1

0

Try this:

SELECT U.userId, U.userName, U.dateOfBirth
FROM Bill B 
JOIN USER U 
GROUP BY U.userId, U.userName, U.dateOfBirth 
ORDER BY SUM(B.moneyOfBill) ASC;
Saharsh Shah
  • 28,687
  • 8
  • 48
  • 83
  • Thanks Saharsh Shah, but I just want to get user data from User table, not bill data. – Bentley Nov 26 '14 at 06:47
  • I found the solution is here http://stackoverflow.com/questions/16354705/hql-join-path-expected-for-join-hibernate. – Bentley Nov 28 '14 at 07:29