6 Replies Latest reply on Jun 3, 2009 1:03 PM by ax man

    issue with @NotAudited and AuditReader queries

    ax man Newbie

      We have an association like

      class Asset {
      .....
      
       @ManyToOne
       @NotAudited
       @JoinTable(name="mte_organization_mte_asset",
       joinColumns = @JoinColumn(name="asset_id"),
       inverseJoinColumns = @JoinColumn(name="organization_id"))
       private Organization organization;
      
      

      along with the asset, organization and asset/org join table. The first issue we had was that we had to add an audit table for the join table, which wasn't a huge issue. The bigger issue now is that AuditReader, when querying for audited assets, is doing an inner join to the audit table for the asset/org join table. There's nothing in that table cuz it's @NotAudited. Is this a bug?

        • 1. Re: issue with @NotAudited and AuditReader queries
          ax man Newbie

          I should clarify: Asset is audited, Organization isn't. However it's appears I'll need to audit Organization to get this to work.

          • 2. Re: issue with @NotAudited and AuditReader queries
            Adam Warski Master

            Hello,

            if Asset is @Audited, but the association to Organization is @NotAudited, then you shouldn't have to create a join table or audit organization. Doesn't this work? If not, what exception are you getting?

            Adam

            • 3. Re: issue with @NotAudited and AuditReader queries
              ax man Newbie

              I get this:

              Caused by: org.hibernate.HibernateException: Missing table: mte_organization_mte_asset_audit
               at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1113)
               at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:139)
               at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:349)
               at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
               at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
               at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
              ... 38 more
              


              that's when I have:
              <entry key="hibernate.hbm2ddl.auto" value="validate"/>
              


              if I change to "auto=none", I get:
              org.hibernate.exception.SQLGrammarException: could not execute query
               at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
               at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
               at org.hibernate.loader.Loader.doList(Loader.java:2231)
               at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2125)
               at org.hibernate.loader.Loader.list(Loader.java:2120)
               at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
               at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361)
               at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
               at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148)
               at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
               at org.hibernate.envers.query.impl.AbstractAuditQuery.buildAndExecuteQuery(AbstractAuditQuery.java:94)
               at org.hibernate.envers.query.impl.RevisionsOfEntityQuery.list(RevisionsOfEntityQuery.java:104)
               at org.hibernate.envers.query.impl.AbstractAuditQuery.getResultList(AbstractAuditQuery.java:100)
               at org.hibernate.envers.reader.AuditReaderImpl.getRevisions(AuditReaderImpl.java:127)
              <snip>
              Caused by: org.postgresql.util.PSQLException: ERROR: relation "mte_organization_mte_asset_audit" does not exist
               at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1525)
               at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1309)
               at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
               at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
               at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:354)
               at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:258)
               at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)
               at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
               at org.hibernate.loader.Loader.getResultSet(Loader.java:1808)
               at org.hibernate.loader.Loader.doQuery(Loader.java:697)
               at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
               at org.hibernate.loader.Loader.doList(Loader.java:2228)
               ... 44 more
              


              • 4. Re: issue with @NotAudited and AuditReader queries
                Adam Warski Master

                Looks like a bug then. Could you create a bug in JIRA for this?

                Thanks,
                Adam

                • 6. Re: issue with @NotAudited and AuditReader queries
                  ax man Newbie

                  while implementing the workaround ( auding Organization) I ran into another problem. Organization has this:

                   @NotAudited
                   @OneToMany(cascade = CascadeType.ALL)
                   @JoinTable(name = "mte_organization_mte_organization", joinColumns = @JoinColumn(name = "parent_organization_id"), inverseJoinColumns = @JoinColumn(name = "child_organization_id"))
                   private List<Organization> organizations = new ArrayList<Organization>();
                  


                  so because of the original problem, I had to add table mte_organization_mte_organization_audit. But now envers is trying to insert into this table with a null REVTYPE (audit_revision_type in our case):

                  could not insert: [com.abc.Organization_audit] [insert into mte_organization_mte_organization_audit (child_organization_id, audit_revision_number) values (?, ?)]
                  org.postgresql.util.PSQLException: ERROR: null value in column "audit_revision_type" violates not-null constraint

                  what conditions would cause envers to not even have the REVTYPE in the insert?