简体   繁体   English

Eclipse Indigo - JPA验证问题

[英]Eclipse Indigo - JPA Validation Problems

I'm using eclipse indigo and am having "JPA Validation Problems". 我正在使用eclipse indigo并且正在进行“JPA验证问题”。

My named query is: 我的命名查询是:

from Person p where p.name = :name

and there is this error: 并且有这个错误:

The query does not start with a valid identifier, has to be either SELECT, UPDATE or DELETE FROM.

But it's a valid JPQL query. 但它是一个有效的JPQL查询。 Somebody know how I can remove this error? 有人知道如何删除此错误?

If I change my query to 如果我将查询更改为

select p from Person p where p.name = :name

there is no more error, but I do not want to change all my queries. 没有更多的错误,但我不想改变我的所有疑问。

thanks 谢谢

mp5 MP5

If you are not concerned with portability, you can turn off the JPQL validation that was added to Dali in the the Indigo release. 如果您不关心可移植性,可以关闭在Indigo版本中添加到Dali的JPQL验证。 If you have a JPA project with the Hibernate platform selected you will still get whatever validtion Hibernate Tools has for JPQL/HQL. 如果你有一个选择了Hibernate平台的JPA项目,你仍然可以获得Hibernate Tools对JPQL / HQL的任何有效性。

Go to workspace preferences 'Java Persistence'->JPA->Errors/Warnings' under 'Queries and generators' and change 'Invalid or incomplete JPQL queries' to 'Ignore'. 转到“查询和生成器”下的工作区首选项“Java持久性” - >“JPA->错误/警告”,并将“无效或不完整的JPQL查询”更改为“忽略”。 You can enter a bug against the Hibernate tools if you would like them to extend the Dali JPQL validation for the Hibernate platform or just to turn it off by default. 如果您希望它们扩展Hibernate平台的Dali JPQL验证或者默认情况下将其关闭,您可以输入针对Hibernate工具的错误。

And indeed that is not a valid JPQL query. 事实上,这不是一个有效的JPQL查询。 JPQL starts with "SELECT", "UPDATE" or "DELETE". JPQL以“SELECT”,“UPDATE”或“DELETE”开头。

Obviously it may work in Hibernate (ie HQL) but that query is not standard and not portable. 显然它可以在Hibernate(即HQL)中工作,但该查询不是标准的,也不是可移植的。 So if you don't want to change your queries then you aren't using JPA, and your app is non-portable. 因此,如果您不想更改查询,那么您不使用JPA,并且您的应用程序是不可移植的。

The JPA spec would confirm this. JPA规范将证实这一点。

It looks to me like any queries that are of the form: 它看起来像任何形式的查询:

from Person p where p.name = :name

Are not in fact valid JPQL. 实际上并不是有效的JPQL。 According to the language reference at: 根据语言参考:

http://docs.oracle.com/javaee/5/tutorial/doc/bnbuf.html http://docs.oracle.com/javaee/5/tutorial/doc/bnbuf.html

each statement needs to have either a SELECT , UPDATE or DELETE statement preceding the FROM portion. 每个语句都需要在FROM部分之前有SELECTUPDATEDELETE语句。

Here are more examples: 以下是更多示例:

http://en.wikipedia.org/wiki/Java_Persistence_Query_Language http://en.wikipedia.org/wiki/Java_Persistence_Query_Language

Unfortunately, it looks like you need to update all the queries to make them fit this format. 不幸的是,您似乎需要更新所有查询以使其符合此格式。

It's not a valid JPQL query. 它不是有效的JPQL查询。 It's a valid HQL query, but HQL ain't JPQL. 这是一个有效的HQL查询,但HQL不是JPQL。 A JPQL query must have a select clause. JPQL查询必须具有select子句。

Here's the BNF syntax of a JPQL clause, from the specifications: 以下是JPQL子句的BNF语法,来自规范:

select_statement :: = select_clause from_clause [where_clause] [groupby_clause [having_clause] [orderby_clause]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM