问题描述
在审计外键时,Envers 似乎忽略了 JoinColumn 注释.
When auditing a foreign key, Envers seems to be ignoring the JoinColumn annotation.
例如我有一个像这样的简单类:
E.g. I have a simple class like this:
@Audited
@Entity
public class Address {
@Id
@GeneratedValue
private int id;
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
@ManyToOne
@JoinColumn (name="addressTypeFk", referencedColumnName="EntityId",nullable=false)
private AddressTypeLookup addressType;
它引用了这样的查找表:
Which references a lookup table like this:
@Entity
public class AddressTypeLookup
{
@Id
@GeneratedValue
private int id;
private String descr;
private int entityId;
请注意,Address 上的 addressType 属性连接到 entityId 列,而不是主键id"列.还要注意 RelationTargetAuditMode.NOT_AUDITED 的使用:我想审计外键,但我不想审计对 AddressTypeLookup 的更改.问题是,当 Envers 记录对外键的更改时,它记录的是 AddressTypeLookup 主键值id",而不是 entityId.如何让 Envers 记录使用的 entityId 值?
Notice that the addressType attribute on Address is joining to the entityId column, not the primary key "id" column. Also notice the use of RelationTargetAuditMode.NOT_AUDITED : I want to audit the foreign key, but I don't want to Audit changes to AddressTypeLookup. The problem is, when Envers records changes to the foreign key, it's recording the AddressTypeLookup primary key value "id", not the entityId. How do I make Envers record the entityId values used?
[如果你想知道为什么我想要这个:我们有一个查找数据(又名主/参考数据)的数据库.它记录历史:所有行都有有效的开始/结束日期.id 列是唯一的;entityId 标识一个特定的东西 - 例如特定地址类型的所有版本.所有查找表都被复制到应用程序数据库中——但只复制当前数据,而不是历史数据.]
[In case you're wondering why I want this: we have a database of lookup data (aka master / reference data). It records history: all rows have effective from/to dates. The id column is properly unique; the entityId identifies a particular thing - e.g. all versions of a particular address type. All the lookup tables are replicated into an application database - but only the current data is replicated, not the historic data. ]
推荐答案
这可能是使用 referencedColumnName 和 RTAM.NOT_AUDITED 的交集的错误.请提交错误报告@https://hibernate.onjira.com/,envers 组件.
This may be a bug with the intersection of using referencedColumnName and RTAM.NOT_AUDITED. Please file a bug report @ https://hibernate.onjira.com/, envers component.
这篇关于Envers,对于带有 JoinColumn 的 ManyToOne,正在审核错误的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!