我是 Hibernate 新手。
当我尝试反转 boolean 值
@Query(value = "更新 ToDo t set t.done= (abs(t.done -1)) where t.id=:id")
public void ToogleDone(@Param("id") long id);
我有一个异常(exception):
[2014-01-20 16:20:38] java.lang.ClassCastException:
java.lang.Integer cannot be cast to java.lang.Long at org.hibernate.type.descriptor.java.LongTypeDescriptor.unwrap(LongTypeDescriptor.java:36) at org.hibernate.type.descriptor.sql.BigIntTypeDescriptor$1.doBind(BigIntTypeDescriptor.java:57) ...
当我尝试这个查询时:
`@Query(value = "更新 ToDo t set t.done= (NOT t.done) where t.id=:id")
public void toogleDone(@Param("id") long id);`
我有异常(exception):
[2014-01-20 16:28:58] unexpected AST node: not [update org.teamdev.todo.model.domain.ToDo t set t.done= (NOT t.done) where t.id=:id]
有人知道在 HQL 中反转 boolean 值吗?
最佳答案
使用set t.done = (t.done=false)
,因此查询将是:
update ToDo t set t.done = (t.done=false) where t.id=:id
关于java - Hibernate HQL 转换 java.lang.ClassCastException : java. lang.Integer 无法转换为 java.lang.Long,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21236759/