简体   繁体   中英

JPQL Query doesn't work

Hello i wanna try to to run this Query

UPDATE WarmTimeMonitoring wtm
SET wtm.warmTime = (EXTRACT(HOUR FROM CURRENT_TIMESTAMP - wtm.entryDate)*60)+ EXTRACT(MINUTE FROM CURRENT_TIMESTAMP - wtm.entryDate )
WHERE wtm.leavingDate IS NULL

When I try the query right on the Database it works

UPDATE WARMTIME_MONITORING w
SET w.WARM_TIME = (EXTRACT(HOUR FROM CURRENT_TIMESTAMP - w.ENTRY_DATE)*60)+ EXTRACT(MINUTE FROM CURRENT_TIMESTAMP - w.ENTRY_DATE)
WHERE LEAVING_DATE IS NULL;

If I try it with JPQL I get the following error:

Exception occurred while performing a database query: IllegalArgumentException-> An exception occurred while creating a query in EntityManager: Exception Description: Syntax error parsing [UPDATE WarmTimeMonitoring wtm SET wtm.warmTime = (EXTRACT(HOUR FROM CURRENT_TIMESTAMP - wtm.entryDate)*60)+ EXTRACT(MINUTE FROM CURRENT_TIMESTAMP - wtm.entryDate ) WHERE wtm.leavingDate IS NULL ]. [68, 85] The left expression is not an arithmetic expression. [131, 148] The left expression is not an arithmetic expression.

Can somebody explain me why this happens and how i can fix it?

And yes I checked that warmTime entryDate and leavingDate are callable.

As @neil stockon said, the some of the functions are not valid JPQL operations, I suggest, first go for the record and get the information needed to make and update

SELECT w.ID, w.ENTRY_DATE from WARMTIME_MONITORING w
WHERE LEAVING_DATE IS NULL;

Once you get the id of the record and the entry_date do the operations you need with the date, to conform the new date and do the JPQL update

UPDATE WARMTIME_MONITORING w
SET w.WARM_TIME = :time
WHERE ID = :id

This could be very inefficient if you have a large amount of data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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