gpt4 book ai didi

mysql - Hibernate JOIN错误语法异常

转载 作者:行者123 更新时间:2023-11-30 22:54:06 25 4
gpt4 key购买 nike

在我的项目(java struts 2,hibernate)中,我想在 2 个表之间进行选择。

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;
}

直接在localhost DB中通过sql尝试就可以了

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

但是我的程序通过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;

eclipse控制台报错:

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)

请帮忙。谢谢!

最佳答案

试试这个:

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;

关于mysql - Hibernate JOIN错误语法异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27141136/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com