2

I am currently learning JPA with Hibernate, using maven as well.

It happens so that I need to use named query's in my orm.xml with a input parameter in the set-clausule of an update statement. It gives me an error that a parameter can only be used in the WHERE or HAVING clausule.

After reading several pages I found out that JPA 2.0 does not support it, but JPA 2.1 does. See this, bulletpoint 4.6.4

So I changed my orm.xml and persistence.xml to the 2.1 schemes as well, but it still gives and error. Although it still runs perfectly, I hate seeing error signs.

Anyone Any idea? I am using Eclipse Kepler 4.3.2

Pictures of orm.xml, persistence.xml, pom.xml and my project properties can be found here

4
  • Can you add some of the code (especially the query) and configuration. Commented Apr 16, 2014 at 7:56
  • 1
    Feel free to direct yourself to the bottom of my post. All pictures of code are there :). It's a basic basic query btw. Commented Apr 16, 2014 at 7:57
  • Sorry, my bad. I need new glasses :) Commented Apr 16, 2014 at 7:59
  • Looks like no1 knows whats happening :p Commented Apr 17, 2014 at 7:10

2 Answers 2

1

I have the same problem, code works fine and it should with JPA 2.1 (Final Release)

http://download.oracle.com/otn-pub/jcp/persistence-2_1-fr-eval-spec/JavaPersistence.pdf In chapter4.6.4 (page 182) find this text (my highlight):

"Input parameters can only be used in the WHERE clause or HAVING clause of a query or as the new value for an update item in the SET clause of an update statement. "

But eclipse validation still take input parameter in update query as an error... Maybe we should raise a bug against org.eclipse.persistence.jpa.jpql

Sign up to request clarification or add additional context in comments.

Comments

0

The following query should work:

<named-query name = "Artikel.findByWord">
    <query>
        UPDATE Artikel a 
        SET a.verkoopprijs = a.verkoopprijs * :percentage
    </query>
</named-query>

with the corresponding java code:

em.createNamedQuery("Artikel.findByWord")
  .setParameter("percentage", 10)
  .executeUpdate();

1 Comment

I am not telling it doesn't work. My code works perfectly, but it is giving an error, where there is none. :) (See my screenshots)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.