1 2 Previous Next 25 Replies Latest reply on Sep 29, 2011 3:48 PM by inna1411 Go to original post
      • 15. Re: CustomEnversListener and Spring
        inna1411

        I tied the way Adam suggested : no errors, but :

         

        1. If I register AuditEventListener, REVINFO table was used and all audit tables populated

        2. If I comment out AuditEventListener and don't specify any other one, audit tables were not populated.

        • 16. Re: CustomEnversListener and Spring
          adamw

          Yes, of course you need to specify the event listener, it's a different thing than the revision entity.

          Is the revision entity in the same jar that all other entities?


          Adam

          • 17. Re: CustomEnversListener and Spring
            inna1411

            Yes, the revision entity (CustomRevisionEntity) resides in the same jar with other regular entities (annotated as @Entity).

            Looks like AuditEventListener is not checking for annotation @RevisionEntity, but just uses REVINFO table by default.

            • 18. Re: CustomEnversListener and Spring
              adamw

              Is the table for CustomRevisionEntity created by Hibernate (provided that your are using hbm2ddl=update or create-drop)?

               

              Adam

              • 19. Re: CustomEnversListener and Spring
                inna1411

                No, I created this table manually, and it resides (revision_info and tables with suffix _aud) in the same database file with auditable tables (it's Firebird; no schemas)

                • 20. Re: CustomEnversListener and Spring
                  adamw

                  Could you try persisting a new CustomRevisionEntity manually, to make sure that Hibernate sees that entity?

                   

                  Adam

                  1 of 1 people found this helpful
                  • 21. Re: CustomEnversListener and Spring
                    inna1411

                    I will try it.

                     

                    What else I tried : I registered my listener CustomEnversListener and modified it this way

                     

                    public class CustomEnversListener implements RevisionListener, PostUpdateEventListener {

                    ...

                        public void onPostUpdate(PostUpdateEvent postUpdateEvent)

                        {

                        }

                    ...

                    }

                     

                    In this case I don't get any errors, update works fine and revision tables not populated (it's understandable why - my onPostUpdate is empty).

                    Looks like all is fine with listener itself; could be the problem persists with CustomRevisionEntity ?

                    • 22. Re: CustomEnversListener and Spring
                      adamw

                      Believe me, the EventListeners don't have anything to do here

                       

                      Adam

                      • 23. Re: CustomEnversListener and Spring
                        inna1411

                        Sure, I believe you !  It's just was a try ... (I saw on web one user mentioned exception will go away if we change the listener this way).

                        I just wanted to make sure the listener "listens".

                        • 24. Re: CustomEnversListener and Spring
                          inna1411

                          Adam,

                           

                          I tried to persist a new CustomRevisionEntity manually, and log contains :

                           

                          .......CustomRevisionEntityHibernate.entity is null false

                          Hibernate: select gen_id( hibernate_sequence, 1 ) from RDB$DATABASE

                          Hibernate: insert into revision_info (REVTSTMP, username, REV) values (?, ?, ?)

                           

                          and table has been populated.

                           

                          But via listener :

                           

                          java.lang.ArrayStoreException: com.etranscor.domain.audit.CustomEnversListener

                                  at org.hibernate.cfg.Configuration.setListener(Configuration.java:1722)

                          • 25. Re: CustomEnversListener and Spring
                            inna1411

                            Adam,

                             

                            all is fine now : the problem was in entity. Don't know how, but it was using hibernate.annotations.Entity instead of javax.persistense.Entity (my word, initially it was right; probably, after manipulating the code for listener I dropped the import statement, and the the wrong one was inserted.)

                             

                            So, for all other users having the same problem :

                             

                            in my case I registered in Spring the default listener  AuditEventListener, created CustomRevisionEntity with annotaion @RevisionEntity(CustomEnversListener.class) &  CustomEnversListener (see code in the beginning of this thread).

                            CustomRevisionEntity I registered in Spring application-context.xml under sessionFactory bean this way :

                             

                                    <property name="annotatedClasses">

                                        <list>

                                            <value>com.etranscor.domain.audit.CustomRevisionEntity</value>

                                        </list>

                                    </property>

                             

                            Please pay attention to import statement for @Entity in  CustomRevisionEntity : it must be "import javax.persistence.Entity;"

                             

                            The only problem left : how to get the real user value (inside the code and manual insert into revision_info table this code worked :

                             

                            String user= SecurityContextHolder.getContext().getAuthentication().getName();

                             

                            But in my jar that keeps only entities, it's null.

                            )

                             

                            Anyway, thank you very much for help and a great hint !

                            1 2 Previous Next