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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13039143/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 11:17:45  来源:igfitidea点击:

JPQL: set a column to null in an update

javajpajpqldatanucleus

提问by AndrewBourgeois

The following JPQL:

以下JPQL:

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

Gives me the following error because of the "= null":

由于“= 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)

But it works when I set the field to an empty string (= '').

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

So how do you set a column to null using JQPL?

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

采纳答案by Yogendra Singh

I think its NULL(in caps) ::Reference JPQLand Eclipselink

我认为它NULL(大写)::Reference JPQLEclipselink

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

Or use param query as :

或使用参数查询为:

     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();