3 Replies Latest reply on Feb 1, 2011 6:38 AM by kontomen2

    Auto flush not work

    kontomen2

      Hi,


      I develop an application, based on Seam 2.2.0.GA, JPA over Hibernate and JBoss AS 5.1. In general, application skeleton was generated by seam-gen and the configuration was not changed so far. I use 4 XA datasources. My problem is that auto flush doesn't work, that is data are not flushed before commit. Of course, I use SMPC and 2 transactions per request approach (default in Seam) and I talk about first transaction. Using TRACE-level logs and breakpoints in proper lines in SessionImpl and PersistenceContexts classes, I already ensured that I have proper flush mode set on all EntityManagers (I tested AUTO and COMMIT). Transaction boundaries are also OK, if log doesn't lie ;). Probably important thing is that flushing works OK in general, for example used in session beans methods, where transaction boundaries are well defines by spec. But when I try to edit some entity (stored in conversation context) using direct binding its properties to JSF controls, changes are not flushed. When I invoke entityManager.flush() manually, on changing screen action, queries are flushed and then persisted thanks to commit before render response phase. All my SMPC are configured like this:




        <persistence:managed-persistence-context auto-create="true" name="entityManager" persistence-unit-jndi-name="java:/my-EntityManagerFactory"/>
        <persistence:managed-persistence-context auto-create="true" name="entityManagerExternal" persistence-unit-jndi-name="java:/my-externalEntityManagerFactory"/>
        ...





      my persistence.xml snippet:




           <persistence-unit name="my-external">
                <provider>org.hibernate.ejb.HibernatePersistence</provider>
                <jta-data-source>java:/myExternalDatasource</jta-data-source>
                <properties>
                     <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
                     <property name="hibernate.show_sql" value="true" />
                     <property name="hibernate.format_sql" value="true" />
                     <property name="jboss.entity.manager.factory.jndi.name" value="java:/my-externalEntityManagerFactory" />
                </properties>
           </persistence-unit>
           ...





      and all datasources defined in JBoss look like this:




        <xa-datasource>
          <jndi-name>myExternalDatasource</jndi-name>
          <xa-datasource-property name="URL">jdbc:mysql://pandora:3306/java?autoReconnect=true&amp;useUnicode=yes&amp;characterEncoding=UTF-8</xa-datasource-property>
          <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
          <user-name>test</user-name>
          <password>test</password>
          <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
          <property name="hibernate.hbm2ddl.auto">update</property>    
          <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
          <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
          <min-pool-size>1</min-pool-size>
          <max-pool-size>10</max-pool-size>
          <idle-timeout-minutes>10</idle-timeout-minutes>
          <metadata>
            <type-mapping>mySQL</type-mapping>
          </metadata>
        </xa-datasource>
        ...





      Can you help me? I spent already 2 days trying to debug this issue and figure out what's going on here but basically have no idea.

        • 1. Re: Auto flush not work
          kontomen2

          I have some additional info about my problem. I've tried to switch my database engine between MySQL and HSQLDB and still doesn't work. Also, I've change all my datasources from XA to local transactional (and disable some code that use more than one datasource) and also doesn't help.

          • 2. Re: Auto flush not work
            kontomen2

            I've just tried to comment out any code that use additional Entity Managers and now I have code that use only the default Entity Manager. So now only one SMPC' EntityManager is created and used and everything is fine. But when I basically instantiate additional EntityManager, auto flush stops to work. Can you help me with this? Should have some additional configuration to handle such situation?

            • 3. Re: Auto flush not work
              kontomen2

              My last post here. I've minimalized application as much as possible. I've just generated new app using seam-gen, created 2 entities and 2 datasources and I'm quite successful in reproducing this strange behaviour in my trivial app as well! When I use this kind of access in my view:




              <h:inputText value="#{user.name}" />





              changes to User entity are not flushed. User is conversation-scoped entity fetched by factory using conversation-scoped entity manager. But when I use this:




              <h:inputText value="#{userHome.instance.name}" />





              it works! What do you think about it? I have no idea why second approach works and first one doesn't.