1 2 Previous Next 20 Replies Latest reply on Feb 26, 2010 1:58 PM by mmagno

    Envers not auditing in Seam entityManager manual flush

      Hi,

       

      I Have used envers before and it worket fine for me.

       

      Now I am trying a seam application, where I set the flush mode as Manual, and syncronizes database with entityManager.Flush.

       

      Using this configuration, I cannot see the audited records been saved on the audit tables or in the revinfo table.

       

      Looking for help I found this new feature request in hibernate issues:http://opensource.atlassian.com/projects/hibernate/browse/HHH-4555

       

      This link talks about auto commit mode = true, but also talks about flushing the entityManager.

       

      Is there any configuration that I am missing?

        • 1. Re: Envers not auditing in Seam entityManager manual flush
          adamw

          Well I don't see any reason why manual flush mode shuoldn't work - in fact I've used Envers in apps with manual flush quite a lot without problems.

           

          I assume you have the listeners configured? And that you use transactions?

          • 2. Re: Envers not auditing in Seam entityManager manual flush
            Hi thanks for the reply,
            The listenners are configured in persistence.xml as show below.
                       <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" />
               <property name="hibernate.ejb.event.pre-collection-update" value="org.hibernate.envers.event.AuditEventListener" />
               <property name="hibernate.ejb.event.pre-collection-remove" value="org.hibernate.envers.event.AuditEventListener" />
               <property name="hibernate.ejb.event.post-collection-recreate" value="org.hibernate.envers.event.AuditEventListener" />
            and the transaction is configured like this
            <property name="hibernate.transaction.manager_lookup_class" value="@transactionManagerLookupClass@"/>
            Can you see anything wrong with this config?
            • 3. Re: Envers not auditing in Seam entityManager manual flush
              adamw

              Hello,

               

              looks fine here. Can you see if the AuditSync.beforeCompletion method is called?

               

              Adam

              • 4. Re: Envers not auditing in Seam entityManager manual flush

                Can you explain further how can I do that ?

                 

                What is the correct way to debug envers ? How can I see the transaction or how can I see envers in action, etc.

                 

                Can you guide me how can I check for this problem?

                • 5. Re: Envers not auditing in Seam entityManager manual flush
                  adamw

                  Here are the steps if you're using maven and idea:

                   

                  If so, you need to download the sources of your dependencies. In idea, this is quite simple, open the right "maven projects" tab, and click on the third button on the top which says "download sources". Then simply open AuditSync in the IDE and place the breakpoint. Execute the application (attaching a remote debugger most possibly and update an entity. If everything is configured properly and if you're using transactions, before commiting you should hit the breakpoint.

                   

                  Adam

                  • 6. Re: Envers not auditing in Seam entityManager manual flush

                    Hi again and thanks again for your time.

                     

                    I am not using maven, can I do the same with eclise ?

                    • 7. Re: Envers not auditing in Seam entityManager manual flush
                      adamw

                      Sure, just download the sources from the website and attach them to your dependencies. I'm not quite sure how you attach a debugger to a running server in eclipse, but I guess it's a fairly simple task.

                       

                      Adam

                      • 8. Re: Envers not auditing in Seam entityManager manual flush

                        Hi Adam,

                         

                        Today I was able to debug my application.

                         

                        I Can see in the deployment of the application that it is calling AuditEventListener.initialize()

                         

                        there I can see that the classes marked with @audit are in the var entCfg.

                         

                        Unfortunately, when I save the entity (entityManager.flush) the auditEventListener events are not called.

                         

                        Can you help me go further?

                        • 9. Re: Envers not auditing in Seam entityManager manual flush
                          adamw

                          So this means that the listenrs are setup correctly.

                           

                          Are you sure that you are using transactions properly? Which container do you use? Do you have JTA configured?

                           

                          Adam

                          • 10. Re: Envers not auditing in Seam entityManager manual flush

                            Hi Adam, Thanks for your patience.

                             

                            This week I was able to go further into my configuration... Also I cleaned a little bit the project in order to know exactaly where I am, because last week I was not able even to tell what type of transactions my project rely on.

                             

                            Lets begin with my configuration:

                            Jboss 4.2.3 GA

                            Jboss Seam 2.2.0 GA (with hibernate 3.3.2)

                            Envers 1.2.2 GA Hibernate 3.3

                             

                            Seam is configured in JPA mode (not EJB) to use a SMPC (Seam Managed Persistence Context), througth an EntityManager.

                            Seam Transaction manager is configured to use JPA RESOURCE_LOCAL transactions with the  javax.persistence.EntityTransaction

                            interface.

                             

                            As I told before, I Have another pure jpa with hibernate project that uses envers and works well, but this one does not uses seam.

                             

                            Above you will find my configuration files. Please tell me if you need further information.

                             

                            persistence.xml

                            <?xml version="1.0" encoding="UTF-8"?>

                            <persistence xmlns="http://java.sun.com/xml/ns/persistence"

                                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                                         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"

                                         version="1.0">

                               <persistence-unit name="pgDatabase" transaction-type="RESOURCE_LOCAL">

                                  <provider>org.hibernate.ejb.HibernatePersistence</provider>

                                  <non-jta-data-source>pgDatasource</non-jta-data-source>

                                  <properties>

                                     <property name="hibernate.hbm2ddl.auto" value="update"/>

                                     <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>

                                     <property name="hibernate.show_sql" value="true"/>

                             

                                     <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>

                                     <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>

                            <!-- Binds the EntityManagerFactory to JNDI where Seam can look it up.

                                          This is only relevant when the container automatically loads the persistence unit, as is the case in JBoss AS 5. -->

                                     <property name="jboss.entity.manager.factory.jndi.name" value="java:/pgEntityManagerFactory"/>

                             

                             

                              <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/> 

                                      

                              <!-- adicionado pra magno para o problema do relatorio  -->

                                      <property name="hibernate.connection.release_mode" value="after_transaction" />  

                                      <property name="hibernate.transaction.flush_before_completion" value="true" />  

                             

                             

                              <!--  Hibernate Envers -->

                                       <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" />

                               <property name="hibernate.ejb.event.pre-collection-update" value="org.hibernate.envers.event.AuditEventListener" />

                               <property name="hibernate.ejb.event.pre-collection-remove" value="org.hibernate.envers.event.AuditEventListener" />

                               <property name="hibernate.ejb.event.post-collection-recreate" value="org.hibernate.envers.event.AuditEventListener" />

                             

                                      <!-- Hibernate Search  -->

                                      <property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.FSDirectoryProvider" />

                                      <property name="hibernate.search.default.indexBase" value="lucene/indexes"/>

                             

                              <!-- Not needed with HA 3.3 -->

                              <property name="hibernate.ejb.event.post-insert" value="org.hibernate.search.event.FullTextIndexEventListener"/>

                            <property name="hibernate.ejb.event.post-update" value="org.hibernate.search.event.FullTextIndexEventListener"/>

                            <property name="hibernate.ejb.event.post-delete" value="org.hibernate.search.event.FullTextIndexEventListener"/>   

                             

                                  </properties>

                               </persistence-unit>

                            </persistence>

                             

                             

                            components.xml
                            <?xml version="1.0" encoding="UTF-8"?>

                            <components xmlns="http://jboss.com/products/seam/components"

                                        xmlns:core="http://jboss.com/products/seam/core"

                                        xmlns:persistence="http://jboss.com/products/seam/persistence"

                                        xmlns:drools="http://jboss.com/products/seam/drools"

                                        xmlns:bpm="http://jboss.com/products/seam/bpm"

                                        xmlns:security="http://jboss.com/products/seam/security"

                                        xmlns:mail="http://jboss.com/products/seam/mail"

                                        xmlns:web="http://jboss.com/products/seam/web"

                                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                                        xmlns:document="http://jboss.com/products/seam/document"

                                        xmlns:transaction="http://jboss.com/products/seam/transaction"

                                        xsi:schemaLocation=

                                            "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.2.xsd

                                             http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.2.xsd

                                             http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.2.xsd

                                             http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.2.xsd

                                             http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.2.xsd

                                             http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.2.xsd

                                             http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.2.xsd

                                             http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.2.xsd

                                             http://jboss.com/products/seam/document http://jboss.com/products/seam/document-2.2.xsd

                                             http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.2.xsd

                                             ">

                             

                            <document:document-store use-extensions="true" error-page="/documentMissing.seam" />

                             

                              <core:init debug="@debug@" jndi-pattern="@jndiPattern@"/>

                             

                               <!-- 600000 = 10 minutos  -->

                               <core:manager

                               concurrent-request-timeout="5000"

                                conversation-timeout="600000"

                                    conversation-id-parameter="cid"

                                    parent-conversation-id-parameter="pid"

                                    default-flush-mode="MANUAL" />

                             

                             

                               <!-- Make sure this URL pattern is the same as that used by the Faces Servlet -->

                               <web:hot-deploy-filter url-pattern="*.seam"/>

                              

                             

                                <transaction:entity-transaction

                                entity-manager="#{entityManager}"/>

                             

                                <persistence:entity-manager-factory

                                name="pgDatabase"

                                installed="true"/>

                             

                                <!-- If Seam loads the persistence unit (JBoss 4.x), the EntityManagerFactory will be resolved from #{pgDatabase}.

                                     On JBoss AS 5, the EntityManagerFactory is retrieved from JNDI (the binding occurs during application deployment). -->

                                <persistence:managed-persistence-context

                                name="entityManager"

                                auto-create="true"

                                   entity-manager-factory="#{pgDatabase}"

                                   persistence-unit-jndi-name="java:/pgEntityManagerFactory"/>

                             

                             

                               <drools:rule-base name="securityRules">

                                  <drools:rule-files><value>/security.drl</value></drools:rule-files>

                               </drools:rule-base>

                             

                               <security:rule-based-permission-resolver security-rules="#{securityRules}"/>

                             

                               <security:identity

                               authenticate-method="#{authenticator.authenticate}"

                               remember-me="true"/>

                             

                               <event type="org.jboss.seam.security.notLoggedIn">

                                  <action execute="#{redirect.captureCurrentView}"/>

                               </event>

                               <event type="org.jboss.seam.security.loginSuccessful">

                                  <action execute="#{redirect.returnToCapturedView}"/>

                               </event>

                             

                             

                            </components>

                            • 11. Re: Envers not auditing in Seam entityManager manual flush
                              adamw

                              Hello,

                               

                              the problem is most probably with this line:

                               

                              <non-jta-data-source>pgDatasource</non-jta-data-source>

                               

                              as you specify that you're not using a JTA-enabled (transational) data source.

                               

                              You most probably need a <local-tx-datasource> in your -ds.xml file and later reference it using <jta-data-source>java:/your_datasource_name</jta-data-source> in persistence.xml.

                               

                              Adam

                              • 12. Re: Envers not auditing in Seam entityManager manual flush

                                Adam Thanks again for your patience.

                                 

                                Following Seams documentation, in order to use Seam with JPA I need to configure the persistence unit using a RESOURCE_LOCAL Transaction type. As you can see in my persistence.xml presented above, the configurations transaction-type="RESOURCE_LOCAL" in the persistence_unit and the  <non-jta-data-source> act as an pair.

                                 

                                As stated in the post above, I am not suposed to use RESOURCE_LOCAL with a <jta-data-source> element

                                http://seamframework.org/Community/SpecificationViolationOnStartupUsingJBoss501GA#comment64829

                                 

                                I do have a pg-ds.xml with a <local-tx-datasource> as pointed bellow. And As I iuse the <use-java-context> element with false value, you will se that in the persistence.xml the line <non-jta-data-source>pgDatasource</non-jta-data-source> points to this database.

                                 

                                <?xml version="1.0" encoding="UTF-8"?>

                                <!DOCTYPE datasources

                                    PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"

                                    "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">

                                <datasources>

                                 

                                   <local-tx-datasource>

                                      <jndi-name>pgDatasource</jndi-name>

                                      <use-java-context>false</use-java-context>

                                      <connection-url>jdbc:postgresql://127.0.0.1:5432/</connection-url>

                                      <driver-class>org.postgresql.Driver</driver-class>

                                 

                                      <user-name>postgres</user-name>

                                      <password>*****</password>

                                   </local-tx-datasource>

                                 

                                </datasources>

                                 

                                 

                                Please note that all persistence in the project is working well, and the database is being bound to the persistence context.

                                 

                                Again, Thank you so mutch for you time and patience in helping me.

                                 

                                Att,

                                Magno

                                • 13. Re: Envers not auditing in Seam entityManager manual flush
                                  adamw

                                  Ah, I see. Could you try switching to jta transactions and see if this helps? Should be just a simple configuration change.

                                   

                                  Adam

                                  • 14. Re: Envers not auditing in Seam entityManager manual flush

                                    As you asked, I changed to JTA transactions. And ensured that I am in a JTA transaction upon commiting the changes to the DB.

                                     

                                    But again, the object is saved in the DB but the AuditEventListener is not called, and nothing is saved in the auditing tables.

                                    1 2 Previous Next