[英]java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long in hibernate
[英]Hibernate HQL casting java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
我是休眠的新手。
當我嘗試反布爾
@Query(value = "update ToDo t set t.done= (abs(t.done -1)) where t.id=:id") public void toogleDone(@Param("id") long id);
我有這個例外:
[2014-01-20 16:20:38] java.lang.ClassCastException:
無法將org.hibernate.type.descriptor.sql.BigIntTypeDescriptor $ 1.doBind上的java.lang.Integer強制轉換為org.hibernate.type.descriptor.java.LongTypeDescriptor.unwrap(LongTypeDescriptor.java:36)上的java.lang.Long (BigIntTypeDescriptor.java:57)...
當我嘗試這個查詢:
`@Query(value =“ update ToDo t set t.done =(NOt t.done)where t.id =:id”)
public void toogleDone(@Param("id") long id);`
我有例外:
[2014-01-20 16:28:58]意外的AST節點:沒有[更新org.teamdev.todo.model.domain.ToDo設置t.done =(NOt t.done)其中t.id =:id]
您是否有人有想法在HQL中逆布爾運算?
您只想切換位值? 您可以使用CASE完成此操作。
update ToDo t set t.done = (case when t.done = 1 then 0 else 1 end) where t.id=:id
使用set t.done = (t.done=false)
,因此查詢將是:
update ToDo t set t.done = (t.done=false) where t.id=:id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.