tim kane created Bug HHH-8066
Issue Type: Bug Bug
Affects Versions: 4.1.10
Assignee: Unassigned
Components: envers
Created: 13/Mar/13 9:23 AM
Description:

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. ]

Project: Hibernate ORM
Priority: Minor Minor
Reporter: tim kane
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira