使用 JPQL 计算关联对象的正确方法
编写此 JPA 查询的正确方法是什么?我只是猜测,因为我无法解决它或在我的 JPA 书中找到它。
Query query=em.createQuery("select m from Meeting m where count(m.attendees) = 0");
return query.getResultList();
我目前正在尝试使用 Hibernate,但出现 mysql 错误!
ERROR org.hibernate.util.JDBCExceptionReporter - You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near ')=0' at line 1
What is the correct way to write this JPA query? I am just guessing as I cant work it out or find it in my JPA book.
Query query=em.createQuery("select m from Meeting m where count(m.attendees) = 0");
return query.getResultList();
I am currently trying this with Hibernate and I get a mysql error!
ERROR org.hibernate.util.JDBCExceptionReporter - You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near ')=0' at line 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要严格回答问题的标题,请使用
SIZE
:来自 JPA 规范:
在
0
的特殊情况下,您还可以使用IS EMPTY
我会测试两者,看看哪一个最有效(检查查询计划)。
To strictly answer the title of the question, use
SIZE
:From the JPA specification:
In the particular case of
0
, you could also useIS EMPTY
I would test both to see which one is the most efficient (check the query plan).