1

For some reason eclipse IDE complains about my JPQL @NamedQuery

Input parameters can only be used in the WHERE clause or HAVING clause of a query.

and

An association field cannot be used in an update items path expression.

this is my query:

"UPDATE ereturn er " +
        "SET " +
        "er.shipper = :shipper, " +
        "er.consignee = :consignee, " +
        "er.notes = :notes, " +
        "er.pickupDateTime = :pickupDate, " +
        "er.productItems = :productItems, " +
        "er.returned = :returned, " +
        "er.returnMethod = :returnMethod, " +
        "er.rma = :rma, " +
        "er.scanDateTime = :scanTime, " +
        "er.status = :status, " +
        "er.dispatchedDate = :dispatchedTime, " +
        "er.barcode = :barcode, " +
        "er.groupName = :groupName " +
        "WHERE er.id = :id"

Any thoughts?

thank you very much

masber
  • 2,875
  • 7
  • 29
  • 49

2 Answers2

0

JPQL is not the best option for update statements, better to just update the object from the persistence context or use native query instead.

I ended up fetching the object through JPQL and modify the object through hiberante dirty checking mechanisim.

masber
  • 2,875
  • 7
  • 29
  • 49
0

If your JPA version is 2.0 or below, you can only use parameters is the WHERE clause.

It changes from version 2.1 and above, as you can see in the section 4.6.4 of the JSR 338: Java TM Persistence API, Version 2.1

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.

Gustavo Passini
  • 2,348
  • 19
  • 25