Here's the code for 2 entities, machine and device.
@Audited
@Entity(name = "device")
@Table(name = "device")
public class Device {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "machineCode", referencedColumnName = "machineCode")
private Machine machine;
}
@Audited
@Entity(name = "machine")
@Table(name = "machine")
public class Machine {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String machineCode;
}
Now, when i save the device entity. The machineCode column (in the auditing table of device) gets the value of id and not the corresponding machineCode from machine's domain object.
I am not sure if there is anything wrong with the code or not. Thanks in advance.
PS - there are other intermingled entities attached to machine entity as well. So, adding @OneToMany is not required or i should say, it would be an overhead.
Edit 1: this question is regarding the envers auditing framework if i didn't make it clear enough.