mp5
mp5

Reputation: 159

Eclipse Indigo - JPA Validation Problems

I'm using eclipse indigo and am having "JPA Validation Problems".

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. 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

Upvotes: 3

Views: 8290

Answers (4)

Karen Butzke
Karen Butzke

Reputation: 1442

If you are not concerned with portability, you can turn off the JPQL validation that was added to Dali in the the Indigo release. If you have a JPA project with the Hibernate platform selected you will still get whatever validtion Hibernate Tools has for JPQL/HQL.

Go to workspace preferences 'Java Persistence'->JPA->Errors/Warnings' under 'Queries and generators' and change 'Invalid or incomplete JPQL queries' to 'Ignore'. 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.

Upvotes: 8

DataNucleus
DataNucleus

Reputation: 15577

And indeed that is not a valid JPQL query. JPQL starts with "SELECT", "UPDATE" or "DELETE".

Obviously it may work in Hibernate (i.e HQL) but that query is not standard and not portable. So if you don't want to change your queries then you aren't using JPA, and your app is non-portable.

The JPA spec would confirm this.

Upvotes: 1

Kevin Bedell
Kevin Bedell

Reputation: 13404

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. According to the language reference at:

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.

Here are more examples:

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.

Upvotes: 1

JB Nizet
JB Nizet

Reputation: 691665

It's not a valid JPQL query. It's a valid HQL query, but HQL ain't JPQL. A JPQL query must have a select clause.

Here's the BNF syntax of a JPQL clause, from the specifications:

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

Upvotes: 1

Related Questions