以下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?
答案 0 :(得分:2)
我认为它是NULL
(在大写字母中)::参考JPQL和Eclipselink
UPDATE SignIn signIn SET signIn.cookieUUID = NULL WHERE signIn.user.id = :userID
或使用param查询:
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();
答案 1 :(得分:0)
这里有similar post(对于HQL)。它应该可以帮助你解决它。
希望它有所帮助。