gpt4 book ai didi

java - JPQL:在更新中将列设置为空

转载 作者:行者123 更新时间:2023-11-30 09:31:01 25 4
gpt4 key购买 nike

以下 JPQL:

UPDATE SignIn signIn SET signIn.cookieUUID = null WHERE signIn.user.id = :userID

由于“= null”而出现以下错误:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IS NULL WHERE `B0`.`ID` = 9' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

但是当我将字段设置为空字符串 (= '') 时它起作用了。

那么如何使用 JQPL 将列设置为空?

最佳答案

我认为它是 NULL(大写)::引用 JPQLEclipselink

 UPDATE SignIn signIn SET signIn.cookieUUID = NULL WHERE signIn.user.id = :userID

或者使用参数查询作为:

     String sQuery = "UPDATE SignIn signIn SET signIn.cookieUUID = :cookieUUID "+
"WHERE signIn.user.id = :userID";
Query query= entityManager.createQuery(sQuery );
query.setParameter("cookieUUID", null);
query.setParameter("userID", userID);
query.executeUpdate();

关于java - JPQL:在更新中将列设置为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13039143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com