1 Reply Latest reply on Sep 27, 2014 4:13 PM by Ulrich Kitzinger

    Sql with wrong columnname in one-to-many association

    Ulrich Kitzinger Newbie

      Hello,

       

      I have a one-to-many association between class A and class C, class C  is derived from class B. Class A is Audited, class C is not.

      B and C are in one table (strategy = InheritanceType.SINGLE_TABLE), with a discrimator in a column named "type".  There are several  other classes derived from B.

       

      Class A has a member "allMyC" of type Set<C>, which holds the association. As C is not audited, this member of  A is marked with @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED). Furthermore, as I want only the Cs, no other subclasses of B, this member is also marked with @Where(clause = "TYPE = 'TypeC'").

      The audit-table for the relation is @AuditJoinTable(name = "A_C_AUD")

      So far so good.

       

      Now when I have an older (audited) revision of class A and try to access allMyC of this revision, the generated sql reads like:

        select

      <several columns>

         from

              A_C_AUD acaud0_,

              C c0_

          where

              (

                  acaud0_.TYPE = 'TypeC'

              )

              and c0_.TYPE='TypeC'

              and acaud0_.id=c0_.id

              and acaud0_.A_ID=?

              and acaud0_.REV=(

                  select

                      max(acaud02_.REV)

                  from

                      A_C_AUD acaud02_

                  where

                      (

                         acaud2_.TYPE = 'TypeC'

                      )

                      and acaud2_.REV<=?

                      and acaud0_.A_id=acaud2_.A_ID

                      and acaud0_.id=acaud2_.id

              )

              and acaud0_.REVTYPE<>?

       

      My problem is in the bold lines:

      There the SQL tries to read a column "TYPE" in the auditing table of the association (which doesn't exist, there's only a "TYPE" column in the table of C), thus producing an sql Error .

       

      When (for test purposes) I leave out the @Where(clause = "TYPE = 'TypeC'") annotation of allMyC, the generated SQl is correct (it's just the same as above, without the boldly marked lines).

       

      What can I do when I want to keep the where-clause? I'm using hibernate envers 4.2.4.

       

      Any hints appreciated.