【发布时间】:2019-05-29 21:56:54
【问题描述】:
我正在将修改后的标志添加到已经存在的审计表中。添加到表中的新修订的标志已正确填写,但我希望已填写现有修订的标志。
我可以在程序上检查更改的修订并更新列,但是为每个表编写特定的过程会花费很多时间。
例如,这是我的user_aud 表中的用户在添加列之前的数据:
id |rev |revtype|username |password
100 |51544|1 |pdacostaporto|420bed36a05fa4668b1baeff18ffce96
100 |46343|0 |pdacostaporto|286755fad04869ca523320acce0dc6a4
当我在 User 实体中将 withModifiedFlag 设置为 true 时:
@Entity
@Audited(withModifiedFlag = true)
public class User {
// Attributes, getters and setters...
}
然后,Hibernate 为标志添加列,但在现有行上使用 null 值,同时按预期为新修订工作:
id |rev |revtype|username |password |username_mod |password_mod
100 |60745|1 |pdacostaporto|4305664d643844973ccb52cbb7c369f8 |false |true
100 |51544|1 |pdacostaporto|420bed36a05fa4668b1baeff18ffce96 |null |null
100 |46343|0 |pdacostaporto|286755fad04869ca523320acce0dc6a4 |null |null
我想用正确的值填充现有行的null 列,如下所示:
id |rev |revtype|username |password |username_mod |password_mod
100 |60745|1 |pdacostaporto|4305664d643844973ccb52cbb7c369f8 |false |true
100 |51544|1 |pdacostaporto|420bed36a05fa4668b1baeff18ffce96 |false |true
100 |46343|0 |pdacostaporto|286755fad04869ca523320acce0dc6a4 |false |false
【问题讨论】:
-
您使用的是哪个数据库平台?
-
@Naros 我正在使用 PostgreSQL 9.5
标签: hibernate jpa hibernate-envers