简体   繁体   English

JPQL查询不起作用

[英]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: 如果我使用JPQL尝试此操作,则会出现以下错误:

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 ]. 执行数据库查询时发生异常:IllegalArgumentException->在EntityManager中创建查询时发生了异常:异常描述:语法错误解析[UPDATE WarmTimeMonitoring wtm SET wtm.warmTime =(EXTRACT(HOUR FROM CURRENT_TIMESTAMP-wtm.entryDate)* 60) + EXTRACT(MINUTE FROM CURRENT_TIMESTAMP-wtm.entryDate)wtm.leavingDate为NULL]。 [68, 85] The left expression is not an arithmetic expression. [68,85]左表达式不是算术表达式。 [131, 148] The left expression is not an arithmetic expression. [131,148]左表达式不是算术表达式。

Can somebody explain me why this happens and how i can fix it? 有人可以解释一下为什么会发生这种情况以及如何解决吗?

And yes I checked that warmTime entryDate and leavingDate are callable. 是的,我检查了warmTime entryDate和leaveingDate是否可调用。

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 正如@neil stockon所说,我建议某些功能不是有效的JPQL操作,首先进行记录并获取制作和更新所需的信息。

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 一旦获得记录的ID和entry_date,就需要对日期进行操作,以符合新日期并进行JPQL更新

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. 如果您有大量数据,这可能会非常低效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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