Question

I'm using jboss envers for the first time and it looks good. It also seems to be easy to use.

However I've come across a problem: when I use the built-in ddl generation to create ddl from my annotated classes, it's creating audit tables for all my classes, not just the ones I want auditing.

For example, I've got a class I've annotated as follows:

@Entity
@Table(name="partner")
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
public class Partner  {

I expect no partner_aud table to be created for this class, because of the annotation.

However, the ddl is created for both partner and partner_aud.

What am I doing wrong?

The ant build config looks like this:

<hibernatetool destdir=".">
<classpath>
<path refid="toolslib" />
  <path location="/Users/matt/workspace/new_Pricing_Tool_PoC/lib/slf4j-api-1.5.8.jar" />
  <path location="/Users/matt/workspace/new_Pricing_Tool_PoC/lib/slf4j-log4j12-1.5.8.jar" />
  <path location="/Users/matt/workspace/new_Pricing_Tool_PoC/bin" />
<fileset dir="new_Pricing_Tool_PoC/lib/">
    <include name="*.jar"/>
  </fileset>
  <pathelement location="classes"/>
  <dirset dir="new_Pricing_Tool_PoC/bin">
    <include name="**/classes/**"/>
  </dirset>
</classpath>
<jpaconfiguration persistenceunit="pricing" />
<hbm2ddl
  drop="false"
  create="true"
  export="false"
  outputfilename="new_Pricing_Tool_PoC/db/auto-build.sql"
  delimiter=";"
  format="true"/>

Also, I have confirmed that hibernate really is using the audit table to store past revisions of the Partner object.

Was it helpful?

Solution

I discovered that this was due to misuse of the @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED) annotation.

By removing this annotation from my class definition, I fixed the problem.

When linking an audited entity to a non-audited entity, you add that annotation to the linking method as in this example:

    @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
    @ManyToOne(optional=false)
    public Partner getPartner() {
        return partner;
    }

This method is taken from Service.java, where Service is audited, but partner not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top