1 2 Previous Next 15 Replies Latest reply on Feb 3, 2014 7:11 AM by sandya2309

    Auditing collection not working

    nick.sree

      Hi,

            I have two entity as follows

       

      Class A


      public class A {

       

           private Set<B> children = new HashSet<B>();

           @AuditMappedBy("parent")

          public Set<B> getChildren() {

                return this.children;

           }

           ..

      }

       

      public class B {

       

           private A parent;

            private Date fromDate;

       

          public A getParent() {

                return this.parent;

           }

           @Audited

           public getFromDate() {

                return this.fromDate;

           }

           ...

      }

       

       

      A.hbm.xml

       

      <hibernate-mapping>

                <class name="A" table="TBL_A">

         ......

      <set name="children " table="TBL_B" inverse="true" access="field" cascade="all-delete-orphan">

                                            <key>

                                                        <column name="ID_A" />

                                   </key>

                <one-to-many class="B" />

      </set>

      ......

       

      B.hbm.xml

       

      <hibernate-mapping>

        <class name="B" table="TBL_B">

         ......

      <many-to-one name="parent" class="A"  cascade="save-update" column="ID_A">

        ......

       

      Now the problem is

       

      A_AUD table does not generating a relationship with B_AUD and vice versa B_AUD doesn't have any relationship with A_AUD, In this case we wont get the child object changes from parent entity.

       

      Can anyone please help me to solve this issue, do i have to do anything else apart from @AuditMappedBy() ?

        • 1. Re: Auditing collection not working
          nick.sree

          Can anyone help me on this, does this work with entity annoated with envers and mapped using hbm file?

          • 2. Re: Auditing collection not working
            adamw

            You don't seem to have @Audited annotations on the collection fields?

             

            Adam

            • 3. Re: Auditing collection not working
              nick.sree

              Hi Adam,

                           No, i have @AuditMappedBy at getter method. (Even i have tried with @Audit insteadof @AuditMappedBy as well)

                  @AuditMappedBy("parent")

                  public Set<B> getChildren() {

                        return this.children;

                   }

               

               

              Infact i have put the envers annoation at getters only (Table is not getting created when i put envers annotation at field level).

              • 4. Re: Auditing collection not working
                adamw

                You need both @Audited and @AuditedMappedBy. @AMB is only an addition.

                 

                Adam

                • 5. Re: Auditing collection not working
                  nick.sree

                  Hi Adam,

                                  I have added both annoation as below but no luck, its not creating any relationship between table A and B

                   

                  @Audited

                  @AuditMappedBy("parent")

                      public Set<B> getChildren() {

                            return this.children;

                       }

                   

                  This is happing only for one-to-many relationship.

                  FYI : i'm using  envers-1.2.2.ga-hibernate-3.3 in hibernate-3.3.1.GA

                  • 6. Re: Auditing collection not working
                    adamw

                    What about the other side of the collection, does "parent" have @Audited as well?

                     

                    Adam    

                    • 7. Re: Auditing collection not working
                      nick.sree

                      Hi Adam,

                                    No i haven't add the annotation at there, since i just want to annote a field in that enity B. Will check  what ever you have mentionedand and update you.

                      • 8. Re: Auditing collection not working
                        nick.sree

                        Hi Adam,

                                       I have put @audited entity at other side of the collection as well. Now  B_AUD table is has added with one more column for parent_id but still there is no relationship established between A_AUD and B_AUD tables. Please let me know what else i have to do,if required i can sent you the full example code for the same issue.

                        • 9. Re: Auditing collection not working
                          adamw

                          Hmm I don't know, it should work. What do you mean by "no relationship established"? What are the annotations now and the content of the _AUD tables?

                           

                          Adam

                          • 10. Re: Auditing collection not working
                            nick.sree

                            What i mean by relationship is, If i add or delet a child from parent its not changing any rev no in parent_aud table.

                            Now my annoated class is like

                             

                            public class A {

                             

                                 private Set<B> children = new HashSet<B>();

                             

                                @Audited

                                @AuditMappedBy("parent")

                                public Set<B> getChildren() {

                                      return this.children;

                                 }

                                 ..

                            }

                             

                            public class B {

                             

                                 private A parent;

                                 private Date fromDate;

                             

                                 @Audited    

                                public A getParent() {

                                      return this.parent;

                                 }

                             

                                 @Audited

                                 public getFromDate() {

                                      return this.fromDate;

                                 }

                                 ...

                            }

                             

                             

                             

                            Pseudo Table data

                             

                            Parent

                             

                            RevNo Id
                            RevType
                            110

                             

                            Child

                             

                            RevNo
                            id
                            RevType
                            110
                            211

                             

                            This Data is the outcome of

                            1) Inserting a parent with one child

                            2) Editing the parent's child (changing only the child data).

                            • 11. Re: Auditing collection not working
                              adamw

                              Well if you change the parent's child (only the child data), then the parent is not modified - that is correct behavior.

                               

                              The parent should only have a new reivsion if new children are added or old ones removed - is that what you are seeing?

                               

                              Adam

                              • 12. Re: Auditing collection not working
                                nick.sree

                                Ok, In that case how we will traverse from parent to child audit history?

                                • 13. Re: Auditing collection not working
                                  adamw

                                  I don't understand - you can get the parent object at the revision when the child was modified and traverse as every other object

                                   

                                  Adam

                                  • 14. Re: Auditing collection not working
                                    nick.sree

                                    If i want to generate an audit report for the parent including audit history of child object, how can i do it in this case? can you please give some idea about the code.

                                    1 2 Previous Next