Hibernate 软删除
2016-05-14 00:00
239 查看
两个实体:Customer:AppUser =1:n
只需配置:@Where(clause="deleted <> '1'")即可
另外在执行删除的时候 写上
@SQLDelete(sql语句)
@SQLDelete(sql="update book set enableflag='false' where id = ?")
//Package name... //Imports... @Entity @Table(name = "CUSTOMER") //Override the default Hibernation delete and set the deleted flag rather than deleting the record from the db. @SQLDelete(sql="UPDATE customer SET deleted = '1' WHERE id = ?") //Filter added to retrieve only records that have not been soft deleted. @Where(clause="deleted <> '1'") public class Customer implements java.io.Serializable { private long id; private Billing billing; private String name; private String address; private String zipCode; private String city; private String state; private String notes; private char enabled; private char deleted; private Set appUsers = new HashSet(0); //Constructors... //Getters and Setters... @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "customer") //Filter added to retrieve only records that have not been soft deleted. @Where(clause="deleted <> '1'") public Set getAppUsers() { return this.appUsers; } public void setAppUsers(Set appUsers) { this.appUsers = appUsers; } }
//Package name... //Imports... @Entity @Table(name = "APP_USER") //Override the default Hibernation delete and set the deleted flag rather than deleting the record from the db. @SQLDelete(sql="UPDATE app_user SET deleted = '1' WHERE id = ?") //Filter added to retrieve only records that have not been soft deleted. @Where(clause="deleted <> '1'") public class AppUser implements java.io.Serializable { private long id; private Customer customer; private AppRole appRole; private char enabled; private String username; private String appPassword; private Date expirationDate; private String firstName; private String lastName; private String email; private String phone; private String fax; private char deleted; private Set persons = new HashSet(0); //Constructors... //Getters and Setters... }
只需配置:@Where(clause="deleted <> '1'")即可
另外在执行删除的时候 写上
@SQLDelete(sql语句)
@SQLDelete(sql="update book set enableflag='false' where id = ?")
相关文章推荐
- SQLite数据库的增删改查
- mysql 修改默认密码
- 编程的哲学思想
- Logistic回归
- STL 优先队列
- 查询每月的天数
- 如何获取不重复的随机数
- 个人工作总结
- 快速排序的递归算法
- 344. Reverse String(将字符串倒序输出)
- 数据持久化-写入plist
- VS中ComboBox取Text值为System.Data.DataRowView的错误
- 从Spark 架构中透视Job
- NumPy常见函数和使用示例
- 基于SSH框架的网上商城的质量属性
- 生活不易,一起努力
- HDFS冗余数据块的自动删除
- 第十二周—阅读程序(3)
- effective objective-c 2.0 笔记 第一章 :熟悉Objective-C
- 一个完整安全的sql上线操作应该是怎样的?!