简体   繁体   中英

Way in hibernate to alter boolean value of column

我如何在休眠中编写类似于以下查询的内容

update tb_image set active = !active;

您应该为此使用本机查询。

You can use:

  1. A separate property for the reversed value and map that property in Hibernate
  2. Entity Listeners and their @PrePersist

First option looks easier and it would be easier to understand it, 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. 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纠正相同的查询。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM