Hi Folks,
I found this very interesting envers project yesterday and stared testing with my current project.
After I configured hibernate and added the annotation @Audited to my classes I startet the application and got this DuplicateMappingException on every @ManyToMany attribute that is refereced from both sides of the relation (The N and the M part).
Does anybody know if this is an issue? I didn't find anything in the forum or the JIRA.
Thanks Mario
PS:
Here is the way I added envers to my Hibernate config:
Code:
AuditEventListener[] auditEventListener = new AuditEventListener[] {new AuditEventListener()};
annotationConfiguration.getEventListeners().setPostInsertEventListeners(auditEventListener);
annotationConfiguration.getEventListeners().setPostUpdateEventListeners(auditEventListener);
annotationConfiguration.getEventListeners().setPostDeleteEventListeners(auditEventListener);
annotationConfiguration.getEventListeners().setPreCollectionUpdateEventListeners(auditEventListener);
annotationConfiguration.getEventListeners().setPreCollectionRemoveEventListeners(auditEventListener);
annotationConfiguration.getEventListeners().setPostCollectionRecreateEventListeners(auditEventListener);
Here is one part of an problematic attribute mapping:
Code:
@Audited
public class Instruction {
...
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "instruction_asset_classes",
joinColumns = { @JoinColumn(name = "instruction_id", nullable = false, updatable = false) },
inverseJoinColumns = { @JoinColumn(name = "asset_class_id", nullable = false, updatable = false) })
public Set<AssetClass> getAssetClasses() {
return this.assetClasses;
}
...
}
Here is the other part of an problematic attribute mapping:
Code:
@Audited
public class AssetClass {
...
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinTable(name = "instruction_asset_classes",
joinColumns = { @JoinColumn(name = "asset_class_id", nullable = false, updatable = false) },
inverseJoinColumns = { @JoinColumn(name = "instruction_id", nullable = false, updatable = false) })
public Set<Instruction> getInstructions() {
return this.instructions;
}
...
}
Here is the exception:
org.hibernate.DuplicateMappingException: Duplicate class/entity mapping instruction_asset_classes_AUD
at org.hibernate.cfg.Mappings.addClass(Mappings.java:141)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:167)
at org.hibernate.cfg.Configuration.add(Configuration.java:702)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:531)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:291)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
at org.hibernate.envers.configuration.AuditConfiguration.getFor(AuditConfiguration.java:102)
at org.hibernate.envers.event.AuditEventListener.initialize(AuditEventListener.java:249)
at org.hibernate.event.EventListeners$1.processListener(EventListeners.java:198)
at org.hibernate.event.EventListeners.processListeners(EventListeners.java:181)
at org.hibernate.event.EventListeners.initializeListeners(EventListeners.java:194)
at org.hibernate.cfg.Configuration.getInitializedEventListeners(Configuration.java:1338)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)