java JPA - 必须为范围变量声明提供标识变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25138744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 07:26:04  来源:igfitidea点击:

JPA - An identification variable must be provided for a range variable declaration

javajpa

提问by richersoon

I wonder why I got "An identification variable must be provided for a range variable declaration." error when I don't have alias.
Seems like I solved by problem when I added alias to the table.

我想知道为什么我得到“必须为范围变量声明提供标识变量”。当我没有别名时出错。
当我向表中添加别名时,似乎我解决了问题。

Code with problem:

有问题的代码:

List result = entityManager.createQuery( "from Rental", Rental.class ).getResultList();

Solution:

解决方案:

List result = entityManager.createQuery( "from Rental r", Rental.class ).getResultList();

采纳答案by Maciej Dobrowolski

You should make a distinction between HQL(Hibernate Query Language) and JPQL(Java Persistence Query Language). As long as your provider is Hibernate you will see no difference, but you have to remember that correct JPQLquery consists of SELECTkeyword. Here'sexplanation of this differences.

您应该区分HQL(Hibernate Query Language) 和JPQL(Java Persistence Query Language)。只要您的提供者是 Hibernate,您就不会看到任何区别,但您必须记住正确的JPQL查询由SELECT关键字组成。这是对这种差异解释。

Going back to you question - it is JPQLrequirement to define alias for each Entity table.

回到你的问题 -JPQL需要为每个实体表定义别名。