[英]Way in hibernate to alter boolean value of column
我如何在休眠中编写类似于以下查询的内容
update tb_image set active = !active;
您应该为此使用本机查询。
You can use: 您可以使用:
First option looks easier and it would be easier to understand it, imo. imo,第一个选项看起来更容易理解。
The simplest answer is that you would already have the entity you need to update loaded, then just set the field as usual. 最简单的答案是,您已经加载了需要更新的实体,然后像往常一样设置字段。
setBool(!isBool())
then commit the change to the DB. setBool(!isBool())
然后将更改提交给数据库。 I'm concerned about your design when you need to operate on the data in the persistent store instead of operating on the objects directly. 当您需要对持久性存储中的数据进行操作而不是直接对对象进行操作时,我担心您的设计。
使用本机查询,因为无法使用Hibernate Query Language纠正相同的查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.