8 Replies Latest reply on Dec 7, 2009 8:38 AM by hernanbolido

    Question about audited super-classes

    hernanbolido

      Hi!

      Scenario:
      - B is a subclass of A
      - B has no envers annotation
      - A has a persistent property called p.

      Situation:
      If I mark the property p of as Audited, envers audits subclass B.
      If mark the whole class A as Audited, envers shows me a NotAuditedException for class B.

      It's easy to test with org.hibernate.envers.test.integration.superclass.MappedSubclassing test. If you move the @Audited from str property of SuperclassOfEntity and put it as class annotation in SuperclassOfEntity, this test fails.
      I wonder which behavior is wrong (if any)... But one is inconsistent with the other, I think...

      Adam, is this correct?

      Hernan.








        • 1. Re: Question about audited super-classes
          adamw

          Hello,

          so both B and A are entities, using some inheritance strategy, or B is a @MappedSuperclass?

          Either way you're right that it's inconsistent, annotating a class should be the same as annotating all properties.

          To prevent users from "accidentally" auditing a subclass, maybe an exception should be thrown. But then, there should be a way to audit only the properties from the superclass, but none from the subclass.

          What do you think, what should be the correct behavior? :)
          Also, could you create a JIRA bug for that?

          Adam

          • 2. Re: Question about audited super-classes
            hernanbolido

            Hi Adam, thanks for your time.


            I tried 2 cases:

            Superclass A mark as @MappedSuperclass.
            Subclass strategy mapping.


            About the correct behavior in this case, I think that the NotAuditedException would be the best option...
            I m thinking in big hierarchies in which you want to audit only one branch. In this cases you should annotate the complete branch from the leaf to the root for auditing the branch you need. And the non annotated branch/leaf will not be audited.
            At the current time in envers, this restriction is not applied; then if you annotates the root at fields/getters level and save an entity from the non audited branch/leaf , you could be auditing it too.
            Do you understand my point?
            So, if you want to audit a subclass, you must mark it as auditable. Otherwise it is not audited.

            What do you think is the best option?

            Thanks again. Hernan.

            • 3. Re: Question about audited super-classes
              adamw

              Yes, I think I agree, as you say, if you want to audit a subclass, it must be marked auditable, but only the properties from superclasses that are either implictly or explicitly annotated as @Audited are audited.

              Could you create a JIRA bug for that? :)

              Adam

              • 4. Re: Question about audited super-classes
                hernanbolido

                Hi Adam!

                Before creating the jiira issue I re-test all cases. That is, all hierarchy mapping strategies and the @MappedSubclass too.
                I did a mistake with the tests before, because the only case that presents this behavior is when there is a @MappedSuperclass in the superclass A.
                So, my original explanation only applies to this case.

                Hernan.

                • 5. Re: Question about audited super-classes
                  adamw

                  So it doesn't work properly with @MappedSuperclass not audited and the subclass not? :)

                  Adam

                  • 6. Re: Question about audited super-classes
                    hernanbolido

                    Hi Adam! Sorry about my mistake.

                    Here is the case. Suppose B is a subclass of A.

                    The subclass B is @Entity and is not audited.
                    The superclass A is @MappedSuperclass.

                    The differents behaviors are:
                    - If A has @Audited at class level, envers does not generate audit info when saving an instance of B.
                    - If A has @Audited at field/getter level, envers generates audit info when saving an instance of B.


                    Thanks again. Hernan.

                    • 7. Re: Question about audited super-classes
                      adamw

                      That's clearly a bug :) Please report it in JIRA. And thanks for the detailed investigation.

                      Adam

                      • 8. Re: Question about audited super-classes
                        hernanbolido

                        Hi!

                        Reported in JIRA as HHH-4646

                        http://opensource.atlassian.com/projects/hibernate/browse/HHH-4646

                        Thanks. Hernan.