Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我如何在hibernate中编写类似于下面的查询
update tb_image set active = !active;
您应该为此使用本机查询。
您可以使用:
第一个选项看起来更容易,而且更容易理解,imo。
最简单的答案是您已经加载了需要更新的实体,然后像往常一样设置该字段。setBool(!isBool())然后将更改提交到数据库。当您需要对持久存储中的数据进行操作而不是直接对对象进行操作时,我会担心您的设计。
setBool(!isBool())
使用本机查询,因为没有办法使用 Hibernate 查询语言来纠正相同的查询。