对于具有JoinColumn的ManyToOne,Envers正在审核错误的列 [英] Envers, for a ManyToOne with JoinColumn, is auditing the wrong column
问题描述
例如,我有一个这样的简单类:
@Audited
@Entity
public class Address {
@Id
@GeneratedValue
private int id;
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
@ManyToOne
@JoinColumn(name =addressTypeFk,referencedColumnName =EntityId,nullable = false)
私人AddressTypeLookup地址类型;
其中引用了一个像这样的查找表:
@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值?
<如果您想知道为什么要这么做:我们有一个查询数据库(即主数据库/参考数据库)。它记录历史记录:所有行都有从/到日期的有效期。 ID列是正确的唯一; entityId标识特定的事物 - 例如所有版本的特定地址类型。所有查找表都被复制到应用程序数据库中 - 但只复制当前数据,而不是历史数据。 ]
这可能是一个使用referencedColumnName和RTAM.NOT_AUDITED的交集的错误。请提交错误报告@ https://hibernate.onjira.com/ ,envers组件。
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;
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?
[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. ]
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.
这篇关于对于具有JoinColumn的ManyToOne,Envers正在审核错误的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!