Considere Employee entity with lastName, codePostal and ID attribut.
I want update lastName with executeUpdate fonction :
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaUpdate<Employee> update = cb.createCriteriaUpdate(Employee.class);
Root<Employee> root = update.from(Employee.class);
Path<String> lastName = root.get("lastName");
Path<Long> id = root.get("id");
update.set(lastName, cb.concat( cb.literal("updated - ") , id.as(String.class)));
update.where(cb.equal(root.get("codePostal"), "32730"));
Query query = em.createQuery(update);
int rowCount = query.executeUpdate();
This code failed with this output :
Error Code: 936
Call: UPDATE EMPLOYEE SET LASTNAME = CONCAT(?, ) WHERE (CODEPOSTAL = ?)
bind => [updated - , 32730]
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commit(EntityTransactionImpl.java:161)
at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517)
... 9 more
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.4.v20190115-ad5b7c6b2a): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: ORA-00936: expression absente
Replacing attribut order
update.set(lastName, cb.concat( cb.literal("updated - ") , id.as(String.class)));
by
update.set(lastName, cb.concat( id.as(String.class), cb.literal(" - updated")));
Execution is succefull, output is
[EL Fine]: sql: 2019-03-05 15:22:28.717--ClientSession(1583992583)--Connection(112026691)--Thread(Thread[main,5,main])--UPDATE EMPLOYEE SET LASTNAME = CONCAT(ID, ?) WHERE (CODEPOSTAL = ?)
bind => [ - updated, 32730]
It seems that in the fist case ID attribut is not set in request.
Does this situation is known ? Something I forget ?