14 Replies Latest reply on Jun 7, 2013 6:40 AM by veitg

    Are there any plans to offer an xml mapping configuration?

    fatefree

      Hello, I just found this project and I would love to use it for our application. However we are unable to use the annotation method because some of our objects are reused across multiple services, and auditing is only required for some of them. I know there was a jira request opened, but it doesn't seem like it was ever assigned. Are there any future plans to offer an hbm or some other xml mapping configuration?

        • 1. Re: Are there any plans to offer an xml mapping configuration?
          adamw

          Hello,

           

          well, putting the @Audited annotations doesn't cause the entities to be automatically audited - for that to hapeen you need two additional things:

          1) envers jar in the classpath

          2) listeners added to the hibernate configuration file

           

          Without that @Audited doesn't have any effect. As this is an annotation, the envers jar doesn't even have to be on the classpath for the entity to be used - the annotations are then completely ingored by java.

           

          As for the xml configuration, there are no plans yet, but it wouldn't be hard to add such a feature, so if you'd like to contribute, I'll be happy to help!

           

          And in either case you can vote on the JIRA.

           

          Adam

          • 2. Re: Are there any plans to offer an xml mapping configuration?
            frankwesterhausen

            Hi guys,

             

            i am following the cml configuration issue for a long time and would be happy to have it ! So I will give it a try to implement it. A few hints would be really nice ! After reading the other posts in the forum and a bit of source my approach is the following:

            -> the starting point is AuditConfiguration class (there the audit meta data is created)

            -> because the xml configuration doesn't support something like @Audited we need a second configuration (for example a custom xml file) to define the the @Audited information

            -> is there a way to read the persistence data envers needs from the entity.hbm.xml files, load the aditional custom xml file with the version information, and combine both to get envers working ?

             

            Any hints are appreciated !

             

            Frank

            • 3. Re: Are there any plans to offer an xml mapping configuration?
              adamw

              Hello,

               

              first, sorry for the late reply - vacation, devoxx and then lots of work kept me away from the forum And thanks for the interest - it would be great to have a contributor for that feature!

               

              I think the best approach is to modularize a bit and allow the audit configuration reading code to be pluggable & configurable via a properties entry.

               

              If you look in EntitiesConfigurator, the point at which annotations are read is AnnotationsMetadataReader (line 77). So you would have to subsitute that for your implementation. The AnnotationsMetadataReader is a class which takes the entity class and returns a description of the audit-related annotations that are on it. Feel free to refactor whatever is needed to achieve the functionality.

               

              Adam

              • 4. Re: Are there any plans to offer an xml mapping configuration?
                frankwesterhausen

                Hi Adam,

                 

                during the last weeks i had time to work on the topic and got one step further I think. I first describe the goal from my point of view and then tell you how far I got up to now:

                 

                Overall Goal:

                Extend the Hibernate Xml Configuration possibilities so that you can define the Envers functionality with it. Interpret and integrate the Envers-Xml-Configuration so that Envers works with Xml configuration.

                 

                Current Goal:

                Write an self defined Xml configuration file which defines the Envers-Configuration. Integrate it in the code so that you can have an Xml configured Hibernate Project and use hibernate by providing the extra xml configuration.

                 

                What is working so far:

                By now I implemented a simple Xml configuration for the Envers part, use it with a simple XML configured Hibernate project and it seems to work. It's still a prototype status and no inheritance is working, this i want to do as the next step !

                 

                Questions:

                At first a short explanation: I took the integration point you mentioned, the AnnotationMetadataReader. I wrote an XmlMetadataReader which reads an Xml-File as a configuration. From that point I look what you did in the annotaion reader try more or less copy the functionality.

                1: For what you need the ModificationStore ? It just cann be the default value or null.

                2: For the possible Envers-Annotations i will code Classes which implement the annotations and fill them with the values from the Xml configuration file.

                3: For the inheritance part: Do you check all superclasses, check if they have audited properties and then add them ? I need a bit more explanation how the inheritance exactly works !

                 

                What would be the best way that you can have a look at the code ? Check out the hibernate project and create a branch ? Any other idea ?

                 

                Frank

                • 5. Re: Are there any plans to offer an xml mapping configuration?
                  adamw

                  Wow, great to see some work here!

                   

                  As for your questions:

                  1. it's not used, I should remove it someday

                  2. yep, there are some imple already in AMR

                  3. well, best to see in the code. The rules are a bit tricky here, depending if you audit the whole class or not. Basically you can audit anything from the hierarchy.

                   

                  As for looking at the code - fork the repo and create pull requests when you're done.

                   

                  Adam

                  • 6. Re: Are there any plans to offer an xml mapping configuration?
                    frankwesterhausen

                    Hi Adam,

                     

                    thank you for the answers ! I have another question. As the entry point you gave me the AnnotationsMetadataReader (line 77). Now I am trying handle the RevisonEntity in the Xml Configuration. For that I think I have to look and rewrite the RevisonInfoConfiguration class (which is created by the AuditConfiguration). I just want to know if I am on the right way ?

                     

                    Frank

                    • 7. Re: Are there any plans to offer an xml mapping configuration?
                      adamw

                      Yes, that's the right class. You could probably extract some common functionality for both (xml&annotation) cases.

                       

                      Adam

                      • 8. Re: Are there any plans to offer an xml mapping configuration?
                        frankwesterhausen

                        Hi Adam,

                         

                        i think did quite well. I just tried to reimplement your configuration by getting the information out of an XML file. I did the following up to now:

                         

                        - definition of an XSD which allows the Envers Configuration in Xml

                        - inserted a global variable which allows to switch between the Xml and the Annotation configuration (the Xml file can be set in another variable)

                        - reimplemented the configuration on Xml basis

                        - adjusted the Ant-Task for DB Schema generation so that its working with Xml configuration

                        - wrote Tests for checking the some functionality: inheritance, components, self defined revision and revision listeners, relations, envers queries (not much so far, just basics)

                         

                        I still have some questions questions:

                         

                        - for what exactly you have the Method AuditPropertiesReader.doGetDeclaredAuditedSuperclasses ? It is just doing something if a class is audited and it has values in the auditParents.

                        - in which case the AuditPropertiesReader.computeAuditConfiguration method is important ? If the the class is not audited it checks if the class is in the declaredSuperclasses, if so it returns the Audit Annotation from

                        PersistenPropertiesSource

                         

                        As the next step i will get the code from github and integrate my code. Do you have branches vor every version ? I need to use Hibernate 3.9 in our project, so it has to run there also.

                        If i checked it in will you take a look at the code ?

                        Did you programm tests which I can adjust so that they can run against Xml configuration ?

                         

                        Frank

                        • 9. Re: Are there any plans to offer an xml mapping configuration?
                          adamw

                          As for the global switch: maybe this can be a configuration property?

                           

                          As for the questions:

                          * doGetDeclaredAuditedSuperclasses: that's to support auditParents. There are cases where you have a superclass and two subclasses, one of which is audited. If you then want to audit the parent of that class as well, but do not audit anything in the second entity, you need the auditParents. So you can specify on an audited entity which superclasses should be audited as well.

                          * doGetDeclaredAuditedSuperclasses - I can't find that method?

                           

                          Hibernate 3.9? You probably mean 3.6?

                          If you check it in I will of course take a look, though I can't make promises on when.

                           

                          There's a lot of tests in the Envers codebase.

                           

                          Adam

                          • 10. Re: Are there any plans to offer an xml mapping configuration?
                            daniel.witkowski

                            Hi,

                             

                            I would also be interested in contributing to this feature. We need to use it with Hibernate 3.6.x branch.

                            As for now I have following problems:

                            1. can not find Envers source code for Hib 3.6

                            Official link on http://www.jboss.org/envers to source code on github (http://github.com/hibernate/hibernate-core/tree/master/hibernate-envers/) does not work

                            Link from documentation (http://docs.jboss.org/hibernate/envers/3.6/reference/en-US/html/source.html) section 9.1 Building from source code - does not work

                             

                            2. Github looks like has only 4.x release

                            Available here: https://github.com/hibernate/hibernate-orm under hibernate-envers project.

                             

                            I am not used to community programming... so I would appreciate some help in finding source code and getting access (if possible) to code that Frank already created.

                             

                            Regards,

                            Daniel

                            • 11. Re: Are there any plans to offer an xml mapping configuration?
                              frankwesterhausen

                              Hi Adam, hi Daniel,

                               

                              Adam:

                              I meant Hibernat eversion number 3.6.9, i forgot the 6.

                              Daniel:

                              It would be really nice to have one more person who wants to implement that feature !!!

                              To contribute you have to clone the hibernate repository, then donwload it locally, then search the git-tag of the 3.6.x version. See also here: https://github.com/hibernate/hibernate-orm/wiki/Contributing-Code. If your are not familiar with git you also need to get used to it.

                              I did that but i have to integrate my work into the repo (started a few month ago without clonig the repo). I hope will finish the integration of my work this week and then we can work togehter on the basis of my work.

                              The building of the complete hibernate project doesn't work on my computer, but the envers-sub project works, that should be enough I think.

                               

                              Frank

                              • 12. Re: Are there any plans to offer an xml mapping configuration?
                                daniel.witkowski

                                Hi Frank,

                                 

                                I was able to fork hibernate-orm, get 3.6.11-snapshot from github,  configure it in eclipse, so it compiles and has no errors and run mvn package to get a working library.

                                So I am set up for adventure :-)

                                 

                                Where do we go from here? Will be you working on your fork or we should create a new and work on one toghether?

                                 

                                Regards,

                                Daniel

                                PS. Sorry for long replay but this is do-it-in-your-free-time kind of project...

                                • 13. Re: Are there any plans to offer an xml mapping configuration?
                                  frankwesterhausen

                                  Hi Daniel,

                                   

                                  I finally made it to push my work. Sorry for the late answer too, I also do this in my free time.

                                  My Repo: https://github.com/frankwesterhausen/hibernate-orm

                                  I made a branch: ENVERS-XML-CONFIGURATION. The points where I jumped in the code are the ones Adam told me. The XSD I made for the XML configuration is under src/main/resources (everything in the envers sub project). The JAXB generated Code to access the Xml configuration I put under  src\main\java\org\hibernate\envers\configuration\metadata\xml\jaxb. With git you will see what i have done so far. Take a look and ask if you have questions.

                                  The next weeks it looks good so that I will have some time to work on the project again. I want to programm some test cases to check the functionallity whick works right now.

                                   

                                  Regards

                                   

                                  Frank

                                  • 14. Re: Are there any plans to offer an xml mapping configuration?
                                    veitg

                                    Any news on this? Did you finish the project or maybe envers has merged your changes into the mainline of development?

                                    We have similar requirements to configure envers through xml.

                                     

                                    Thanks.