12 Replies Latest reply on May 20, 2009 12:45 PM by dave_lilley

    Annotation / persistence.xml question

      We have migrated our project to:

      JBoss 5.0.1
      Hibernate 3.3
      Seam 2.11
      Granite 1.2
      Flex 3.x
      Envers 1.2

      With the post-insert, post-update, and post-delete, auditing is working properly. The problem is that we also have listeners which fire to update data for a JMS client. When the AuditEventListener is defined in persistence.xml, the listeners for JMS do not fire. It is as if AuditEventListener consumes the event, but does not refire or let another consumer have it. We need both event listeners to catch it.

      I tried to add AuditEventListener to the Entity Listener annotation in our Abstract (e.g. @EntityListeners({AuditEventListener.class, JmsListener.class}), but that doesn't work.

      Is there any way to allow both listeners to work?

        • 1. Re: Annotation / persistence.xml question

          BTW, if we disable auditing, the JMS listener works.

          • 2. Re: Annotation / persistence.xml question
            adamw

            Hello,
            well, you should specify all listeners in persistence.xml. For example, if you are using Envers and EJB3, then if you want the @PostX and @PreX callback to work, you have to specify both the EJB3 listener and Envers listener; in post-insert, that would be:

            org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener
            

            What exactly are the "JMS listeners"?

            Adam

            • 3. Re: Annotation / persistence.xml question

              My bad. I should have put JMS listeners in quotes.

              Or better yet, what I should have said is that we have created a custom class that is annotated on @EntityListeners. The custom class has methods annotated with @PostPersist, @PostRemove, and @PostUpdate respectively.

              When triggered, the methods raises events that are handled by an observer. The observer takes the object and message and publishes them to a JMS topic, which is subscribed to by a Flex Client.

              When I put the Envers event listeners in persistence.xml, the class on the @EntityListeners annotation is not called.

              • 4. Re: Annotation / persistence.xml question

                Note: When I changed our entity listener class to an event listener, added code to exclude audit entities, and put the new listener in persistence.xml, both listeners worked.

                My question now is, why does the audit event listener seem to short circuit an entity listener specified on an entity via an annotation.

                • 5. Re: Annotation / persistence.xml question

                  ...if needed I could produce an test case and submit a jira.

                  • 6. Re: Annotation / persistence.xml question
                    adamw

                    Hello,

                    did you include the default listeners in your persistence.xml?

                    <property name="hibernate.ejb.event.post-insert"
                     value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener" />
                     <property name="hibernate.ejb.event.post-update"
                     value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener" />
                     <property name="hibernate.ejb.event.post-delete"
                     value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener" />
                    


                    Also, what do you mean by "adding code to exclude audit entities"? :)

                    Adam

                    • 7. Re: Annotation / persistence.xml question

                      We are using SEAM, so as I understand it, the EJB3 listener isn't required.

                      I had the AuditEventListener in persistence.xml. The problem is that when I add the AuditEventListener in persistence.xml, the @EntityListeners specified on the annotation no longer works.

                      • 8. Re: Annotation / persistence.xml question
                        adamw

                        Hello,
                        well, but you are using JPA (as I understand), which is a part of EJB3, so you need the EJB3 listeners for the @EntityListneres/@PostX callbacks to work.

                        Adam

                        • 9. Re: Annotation / persistence.xml question

                          I will re-read the documentation, but we are using SEAM annotations, and it has worked until now.

                          • 10. Re: Annotation / persistence.xml question
                            adamw

                            Hello,

                            you lost me :). What is the package of the @EntityListeners annotation you use? And what "seam annotations" regarding entities do you use?

                            Did you try configuring the listeners including the EJB3 and Envers one?

                            Adam

                            • 11. Re: Annotation / persistence.xml question

                              Adam,

                              You were right. Thanks for your help.

                              Dave

                              • 12. Re: Annotation / persistence.xml question

                                 

                                "adamw" wrote:
                                Hello,

                                you lost me :). What is the package of the @EntityListeners annotation you use? And what "seam annotations" regarding entities do you use?

                                Did you try configuring the listeners including the EJB3 and Envers one?

                                Adam


                                On our abstract entity is the root for all of our entities, we have an entity listener from javax.persistence.EntityListeners.

                                When I added the EJB3 event listeners in persistence.xml, the entity listeners worked.

                                Thanks again,
                                Dave