10 Replies Latest reply on Feb 1, 2012 2:16 AM by adamw

    Bidirectional associations and hierarchies

    hernanbolido

      Hi!

       

      I came upon this situation: Suppose a simple class hierarchy where A is the superclass and A1 and A2 are subclass of A (A1 and A2 are "sisters").

       

      There is another class B which has a collection of A1 instances and different a collection of A2 instances. Super class A has the bidirectional relation to B.

       

      The mapping in B is one-to-many for both collections with invers=true.

      The mapping in A is many-to-one for the inverse side.

       

      When envers tries to find the mappedBy property (which is defined in A) inside A1 or A2, fails because there is no property indicated by "mappedBy". It´s because the mappedBy attribute is defined in the superclass A.

       

      I found that in CollectionMetadataGenerator.getMappedBy(Collection collectionValue) envers looks for mappedBy only in the referenced class and no on its superclasses. I added the code for searching on superclasses if the referenced class hasn´t the attribute and worked fine.

       

      What do you think about? It´s expected to work only with the referenced class info or we need to inspect superclasess as well ?

       

      I´m attaching a test case.

       

      Regards. Hernán.

        • 1. Re: Bidirectional associations and hierarchies
          adamw

          Hello,

           

          that's most probably a bug.

          Could you create a JIRA issue and attach the patch there, and assign it to me?

          I'll apply the patch as soon as I get home (which hopefully won't involve any volcanoes this time )

           

          Adam

          1 of 1 people found this helpful
          • 2. Re: Bidirectional associations and hierarchies
            adamw

            Did you maybe create a JIRA for that?

             

            Adam

            • 3. Re: Bidirectional associations and hierarchies
              hernanbolido

              Hi Adam, welcome back!

               

               

              Not yet! I´m working on it.

               

               

              Hernán.

              • 4. Re: Bidirectional associations and hierarchies
                hernanbolido

                Hi!

                 

                I've created the jira issue HHH-5195

                 

                I uploaded two patches, one containing the test cases and another with some modifications in CollectionMetadataGenerator.

                 

                 

                Hope it will help.

                 

                 

                Thanks. Hernán.

                • 5. Re: Bidirectional associations and hierarchies
                  hernanbolido

                  I saw that the patch was commited.

                   

                  Great! Thanks!

                   

                  Hernán.

                  • 6. Re: Bidirectional associations and hierarchies
                    anshuiitk1

                    Hello Adam,

                     

                    I get the similar error ,

                     

                    Caused by: org.hibernate.MappingException: @AuditMappedBy points to a property that doesn't exist: x.y.EnityClass.auditMappedByProperty

                     

                    but at a different point.

                     

                    ClassesAuditingData.forcePropertyInsertable(ClassesAuditingData.java:83)

                    ClassesAuditingData.updateCalculatedFields() line: 69

                    EntitiesConfigurator.configure(Configuration, ReflectionManager, GlobalConfiguration, AuditEntitiesConfiguration, Document, Element) line: 84

                    AuditConfiguration.<init>(Configuration) line: 86

                    AuditConfiguration.getFor(Configuration) line: 99

                    CustomAuditEventListener(AuditEventListener).initialize(Configuration) line: 335

                    EventListeners$1.processListener(Object) line: 198

                    EventListeners.processListeners(EventListeners$ListenerProcesser) line: 181

                    EventListeners.initializeListeners(Configuration) line: 194

                    AnnotationConfiguration(Configuration).getInitializedEventListeners() line: 1396

                    AnnotationConfiguration(Configuration).buildSessionFactory() line: 1385

                    AnnotationConfiguration.buildSessionFactory() line: 954

                    Ejb3Configuration.buildEntityManagerFactory() line: 892

                    HibernatePersistence.createContainerEntityManagerFactory(PersistenceUnitInfo, Map) line: 74

                     

                    I am using hibernate 3.5.6.

                     

                    To me it doesnt explains, how could you, not get this error, but the error which Hernan reported.

                    This could only happen, if it was introduced in the later builds of 3.5.2 (where HHH-5191 is fixed), and Hernan still uses 3.5.2 and not the later builds where it is was introduced.

                     

                    The reason I say this is because, If You see the Call Hierarchy of CollectionMetaDataGenerator.getMappedBy, it would collide on EntitiesConfigurator.configure at line number 100.

                    Whereas the error I get occurs much before in EntitiesConfigurator.configure at line number 84.

                     

                    As a workaround, I could still not use auditmappedby annotation, and live with the assosiation table.

                     

                    But, Please help provide a solution.

                     

                    Thanks,

                    • 7. Re: Bidirectional associations and hierarchies
                      anshuiitk1

                      Hello Adam,

                       

                      I just Attached the Modifed ClassesAuditingData.java file. This helps solve the problem I mentioned. Could this be accepted as a patch in 3.5.6 ?. Please let me know, the feedback on the patch.

                       

                      Thanks,

                      Himanshu.

                      • 8. Re: Bidirectional associations and hierarchies
                        adamw

                        There's no more development for the 3.5 branch unforutnately.

                         

                        Adam

                        • 9. Re: Bidirectional associations and hierarchies
                          anshuiitk1

                          Hello Adam .. Thanks for the reply ..

                           

                          I took a look at the source code of 4.0.1. It looks like the same problem would occur in the ClassesAuditingData.java. The problem would still prevail.

                           

                          If you could confirm this to be a problem, then it is possible to track the issue on Jira. I have attached the ClassesAuditingData.java with my previous posting. It works well with my use case. May be, it could be accepted as a possible solution.

                           

                          Please let me know.

                          • 10. Re: Bidirectional associations and hierarchies
                            adamw

                            Can you try creating an Envers test case demonstrating the problem and attaching it to JIRA?

                             

                            Adam