Problem Auditing Elements in bi-directional relationships
croqueteer Sep 10, 2010 11:19 AMHi,
I have a problem with auditing elements contained in a Set.
http://docs.jboss.org/envers/docs/index.html#exceptions-onetomanyjoincolumn
I do not use a join table.
I am using Envers (3.5.5.Final) with JPA and Spring (3.0.3.RELEASE)
These are my entities:
@Entity
@Table(name="OPERATOR")
@Audited
public class Operator {
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "OPERATOR_ID", nullable=false)
@AuditMappedBy(mappedBy="operator")
private Set<ConfigGroup> configGroups;
Getters & Setters....
}
@Entity
@Table(name="CONFIG_GROUP")
@Audited
public class ConfigGroup {
@ManyToOne
@JoinColumn(name="OPERATOR_ID", insertable=false, updatable=false, nullable=false)
private Operator operator;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "CONFIG_GROUP_ID",nullable=false)
@AuditMappedBy(mappedBy="configGroup")
private Set<Config> configs;
Getters & Setters....
}
@Entity
@Table(name = "CONFIG_VALUE")
@Audited
public class Config {
@ManyToOne
@JoinColumn(name="CONFIG_GROUP_ID", insertable=false, updatable=false, nullable=false)
private ConfigGroup configGroup;
Getters & Setters....
}
Now when I first persist my object graph i.e entityManager.persist(operator) everything is stored neatly and audited.
If I then update my object graph by adding a few elements (i.e add a new ConfigGroup to Operator and the ConfigGroup contains a new Config) and then call entityManager.merge(operator). The new objects are properly stored by Hibernate, insert statements seems ok. But the new config element in the new ConfigGroup is never audited. The config group itself gets audited but not the contained Config. In the log I do not see an insert statement for the new Config object to its audit table.
Earlier I had a problem where the ConfigGroup did not get audited even though an insert statement was logged.
I managed to work around that one, but there also seems to be some issues with transactions... (I got insert statement and a new id was claimed/used from a db sequence)
Any help would be greatly appreciated!
Best regards,
Henrik