2 Replies Latest reply on Nov 18, 2010 7:38 AM by Joao Cunha

    Spring - Tomcat - Hibernate Transaction not committed with new Entity

    Fatih Algan Newbie

      Hi;


      I am relatively new to Seam and I have a strange situation here. I am using Tomcat, Hibernate(not JPA), and Spring integration for Data Access Layer(DAO).. Below are snippets from my config;


      Hibernate-config:
      <property name="show_sql">true</property>
      <property name="dialect">org.hibernate.dialect.OracleDialect</property>
      <property name="connection.datasource">java:comp/env/jdbc/csv</property>
      <property name="transaction.flush_before_completion">true</property>
      <property  name="transaction.factory_class">
      org.hibernate.transaction.JDBCTransactionFactory</property>
      <property name="query.substitutions">true</property>
      <property name="use_outer_join">true</property>
      <property name="max_fetch_depth">5</property>
      <property name="bytecode.use_reflection_optimizer">true</property>
      <property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>


      components.xml:
      <core:manager concurrent-request-timeout="500"
                      conversation-timeout="120000" conversation-id-parameter="cid"
                      parent-conversation-id-parameter="pid"/>

      <spring:context-loader config-locations="/WEB-INF/csvApplicationContext.xml"/>
             
      <persistence:hibernate-session-factory name="csvSessionFactory" />

      <persistence:managed-hibernate-session name="csvHibernateSession" session -factory="#{csvSessionFactory}" />

      <transaction:hibernate-transaction session="#{csvHibernateSession}" />



      Spring ApplicationContext:
      <bean id="csvSessionFactory" class="org.jboss.seam.ioc.spring.SeamManagedSessionFactoryBean">
                      <property name="sessionName" value="csvHibernateSession"/>
              </bean>
              <bean id="csvHibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
              <property name="sessionFactory">
                  <ref bean="csvSessionFactory"/>
                      </property>
          </bean>
          <bean id="csvDaoTemplate" abstract="true">
              <property name="hibernateTemplate">
                  <ref bean="csvHibernateTemplate"/>
                      </property>
              </bean>
              <bean id="securityDao" class="csv.security.dao.SecurityDao" parent="csvDaoTemplate"/>


      Now, I have a pages scoped POJO service layer object which queries, updates and deletes Module entities.



      @Name("moduleListAction")
      @Scope(ScopeType.PAGE)
      public class ModuleListAction implements Serializable {

      @Logger
      private Log logger;
             
      @In
      FacesMessages facesMessages;
             
      @In("#{securityDao}")
      private SecurityDao securityDao;
             
      @DataModel
      private List<Module> moduleList;
             
      @DataModelSelection()
      private Module selectedModule = new Module();

      @Factory(value="moduleList")
      public void searchModules() {
              moduleList = securityDao.findAllModules();
      }
             
      public void editModule() {
              logger.debug("Editing Module: " + selectedModule.getModuleName());             
      }
             
      public void newModule() {
              selectedModule = new Module();
      }
             
      public void deleteModule() {
              securityDao.delete(selectedModule);
              moduleList = null;
      }
             
             
      public void saveModule() {
              securityDao.saveOrUpdate(selectedModule);
              moduleList = null;
      }
      }

      Now, when I click editModule from the web page, the editModule() is called. It principally does nothing because the selected module object is already caught by @DataModelSelection.
      When I clieck newModule from the web page, a new Module object is created, so that when saveModule() is clicked on the next request, it can be saved.


      The strange thing is the edit functionality works OK here, but when I try to create a new module, the transaction is not committed, though in both cases it is the same method that is called(saveModule)..


      Below is a trace of my log file, when trying to create a new Module:



      |15/02 14:58:39 DEBUG - SeamPhaseListener.begin(592) | beginning transaction prior to phase: APPLY_REQUEST_VALUES 2
      15/02 14:58:39 DEBUG - HibernateTransaction.begin(78) | beginning Hibernate transaction
      15/02 14:58:39 DEBUG - SessionImpl.<init>(247) | opened session at timestamp: 5186513795604480
      15/02 14:58:39 DEBUG - ManagedHibernateSession.initSession(96) | created seam managed session for session factory: java:/csvHibernateSession
      15/02 14:58:39 DEBUG - JDBCTransaction.begin(82) | begin
      15/02 14:58:39 DEBUG - ConnectionManager.openConnection(444) | opening JDBC connection
      15/02 14:58:39 DEBUG - JDBCTransaction.begin(87) | current autocommit status: true
      15/02 14:58:39 DEBUG - JDBCTransaction.begin(90) | disabling autocommit
      15/02 14:58:39 DEBUG - Component.getValueToInject(2298) | trying to inject with hierarchical context search: facesMessages
      15/02 14:58:39 DEBUG - Component.getValueToInject(2290) | trying to inject with EL expression: #{securityDao}
      15/02 14:58:39 DEBUG - AbstractBeanFactory.doGetBean(214) | Returning cached instance of singleton bean 'securityDao'
      15/02 14:58:39 DEBUG - Component.injectDataModelSelection(1637) | selected row: null
      15/02 14:58:39 DEBUG - Component.getValueToInject(2298) | trying to inject with hierarchical context search: facesMessages
      15/02 14:58:39 DEBUG - Component.getValueToInject(2290) | trying to inject with EL expression: #{securityDao}
      15/02 14:58:39 DEBUG - AbstractBeanFactory.doGetBean(214) | Returning cached instance of singleton bean 'securityDao'
      15/02 14:58:39 DEBUG - Component.injectDataModelSelection(1637) | selected row: null
      15/02 14:58:39 DEBUG - Component.getValueToInject(2298) | trying to inject with hierarchical context search: facesMessages
      15/02 14:58:39 DEBUG - Component.getValueToInject(2290) | trying to inject with EL expression: #{securityDao}
      15/02 14:58:39 DEBUG - AbstractBeanFactory.doGetBean(214) | Returning cached instance of singleton bean 'securityDao'
      15/02 14:58:39 DEBUG - Component.injectDataModelSelection(1637) | selected row: null
      15/02 14:58:39 DEBUG - Component.getValueToInject(2298) | trying to inject with hierarchical context search: facesMessages
      15/02 14:58:39 DEBUG - Component.getValueToInject(2290) | trying to inject with EL expression: #{securityDao}
      15/02 14:58:39 DEBUG - AbstractBeanFactory.doGetBean(214) | Returning cached instance of singleton bean 'securityDao'
      15/02 14:58:39 DEBUG - Component.injectDataModelSelection(1637) | selected row: null
      15/02 14:58:39 DEBUG - Component.getValueToInject(2298) | trying to inject with hierarchical context search: facesMessages
      15/02 14:58:39 DEBUG - Component.getValueToInject(2290) | trying to inject with EL expression: #{securityDao}
      15/02 14:58:39 DEBUG - AbstractBeanFactory.doGetBean(214) | Returning cached instance of singleton bean 'securityDao'
      15/02 14:58:39 DEBUG - Component.injectDataModelSelection(1637) | selected row: null
      15/02 14:58:39 DEBUG - Component.getValueToInject(2298) | trying to inject with hierarchical context search: facesMessages
      15/02 14:58:39 DEBUG - Component.getValueToInject(2290) | trying to inject with EL expression: #{securityDao}
      15/02 14:58:39 DEBUG - AbstractBeanFactory.doGetBean(214) | Returning cached instance of singleton bean 'securityDao'
      15/02 14:58:39 DEBUG - Component.injectDataModelSelection(1637) | selected row: null
      15/02 14:58:39 DEBUG - Component.getValueToInject(2298) | trying to inject with hierarchical context search: facesMessages
      15/02 14:58:39 DEBUG - Component.getValueToInject(2290) | trying to inject with EL expression: #{securityDao}
      15/02 14:58:39 DEBUG - AbstractBeanFactory.doGetBean(214) | Returning cached instance of singleton bean 'securityDao'
      15/02 14:58:39 DEBUG - Component.injectDataModelSelection(1637) | selected row: null
      15/02 14:58:39 DEBUG - Component.getValueToInject(2298) | trying to inject with hierarchical context search: facesMessages
      15/02 14:58:39 DEBUG - Component.getValueToInject(2290) | trying to inject with EL expression: #{securityDao}
      15/02 14:58:39 DEBUG - AbstractBeanFactory.doGetBean(214) | Returning cached instance of singleton bean 'securityDao'
      15/02 14:58:39 DEBUG - Component.injectDataModelSelection(1637) | selected row: null
      15/02 14:58:39 DEBUG - Component.getValueToInject(2298) | trying to inject with hierarchical context search: facesMessages
      15/02 14:58:39 DEBUG - Component.getValueToInject(2290) | trying to inject with EL expression: #{securityDao}
      15/02 14:58:39 DEBUG - AbstractBeanFactory.doGetBean(214) | Returning cached instance of singleton bean 'securityDao'
      15/02 14:58:39 DEBUG - Component.injectDataModelSelection(1637) | selected row: null
      15/02 14:58:39 DEBUG - SessionFactoryUtils.doGetSession(318) | Opening Hibernate Session
      15/02 14:58:39 DEBUG - SeamLifecycleUtils.beginTransactionalSeamCall(33) | Application available.  Won't start a new call
      15/02 14:58:39 DEBUG - HibernateTransaction.registerSynchronization(184) | registering synchronization: ManagedHibernateSession(java:/csvHibernateSession)
      15/02 14:58:39 DEBUG - AbstractBatcher.logOpenPreparedStatement(410) | about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
      15/02 14:58:39 DEBUG - SQLStatementLogger.logStatement(111) | select SEQ_SECURITY.nextval from dual
      Hibernate: select SEQ_SECURITY.nextval from dual
      15/02 14:58:39 DEBUG - SequenceGenerator.generate(105) | Sequence identifier generated: 1121
      15/02 14:58:39 DEBUG - AbstractBatcher.logClosePreparedStatement(418) | about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
      15/02 14:58:39 DEBUG - AbstractSaveEventListener.saveWithGeneratedId(135) | generated identifier: 1121, using strategy: org.hibernate.id.SequenceGenerator
      15/02 14:58:39 DEBUG - HibernateAccessor.flushIfNecessary(389) | Eagerly flushing Hibernate session
      15/02 14:58:39 DEBUG - AbstractFlushingEventListener.prepareEntityFlushes(134) | processing flush-time cascades
      15/02 14:58:39 DEBUG - AbstractFlushingEventListener.prepareCollectionFlushes(177) | dirty checking collections
      15/02 14:58:39 DEBUG - Collections.processReachableCollection(199) | Collection found: [csv.security.domain.Module.operations#1121], was: [<unreferenced>] (initialized)
      15/02 14:58:39 DEBUG - AbstractFlushingEventListener.flushEverythingToExecutions(108) | Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
      15/02 14:58:39 DEBUG - AbstractFlushingEventListener.flushEverythingToExecutions(114) | Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
      15/02 14:58:39 DEBUG - Printer.toString(106) | listing entities:
      15/02 14:58:39 DEBUG - Printer.toString(113) | csv.security.domain.Module{id=1121, description=YTYYY, moduleName=XXXX, operations=[]}
      15/02 14:58:39 DEBUG - AbstractBatcher.logOpenPreparedStatement(410) | about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
      15/02 14:58:39 DEBUG - SQLStatementLogger.logStatement(111) | insert into MODULE (MODULENAME, DESCRIPTION, ID) values (?, ?, ?)
      Hibernate: insert into MODULE (MODULENAME, DESCRIPTION, ID) values (?, ?, ?)
      15/02 14:58:39 DEBUG - BatchingBatcher.doExecuteBatch(66) | Executing batch size: 1
      15/02 14:58:39 DEBUG - Expectations$BasicExpectation.checkBatched(77) | success of batch update unknown: 0
      15/02 14:58:39 DEBUG - AbstractBatcher.logClosePreparedStatement(418) | about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
      15/02 14:58:39 DEBUG - SessionFactoryUtils.closeSession(789) | Closing Hibernate Session
      15/02 14:58:39 DEBUG - SeamManagedSessionFactoryBean$SeamManagedSessionHandler.invoke(292) | Closing Session Proxy.
      15/02 14:58:39 DEBUG - SessionImpl.disconnect(401) | disconnecting session
      15/02 14:58:39 DEBUG - ConnectionManager.closeConnection(464) | releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
      15/02 14:58:39 DEBUG - SeamPhaseListener.commitOrRollback(612) | committing transaction after phase: INVOKE_APPLICATION 5
      15/02 14:58:39 DEBUG - HibernateTransaction.commit(95) | committing Hibernate transaction
      15/02 14:58:39 DEBUG - JDBCTransaction.commit(134) | commit
      15/02 14:58:39 DEBUG - AbstractFlushingEventListener.prepareEntityFlushes(134) | processing flush-time cascades
      15/02 14:58:39 DEBUG - AbstractFlushingEventListener.prepareCollectionFlushes(177) | dirty checking collections
      15/02 14:58:39 DEBUG - Collections.processReachableCollection(199) | Collection found: [csv.security.domain.Module.operations#1121], was: [csv.security.domain.Module.operations#1121] (initialized)
      15/02 14:58:39 DEBUG - AbstractFlushingEventListener.flushEverythingToExecutions(108) | Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
      15/02 14:58:39 DEBUG - AbstractFlushingEventListener.flushEverythingToExecutions(114) | Flushed: 0 (re)creations, 0 updates, 0 removals to 1 collections
      15/02 14:58:39 DEBUG - Printer.toString(106) | listing entities:
      15/02 14:58:39 DEBUG - Printer.toString(113) | csv.security.domain.Module{id=1121, description=YTYYY, moduleName=XXXX, operations=[]}
      15/02 14:58:39 DEBUG - ConnectionManager.openConnection(444) | opening JDBC connection
      15/02 14:58:39 DEBUG - JDBCTransaction.toggleAutoCommit(227) | re-enabling autocommit
      15/02 14:58:39 DEBUG - JDBCTransaction.commit(147) | committed JDBC Connection
      15/02 14:58:39 DEBUG - ConnectionManager.aggressiveRelease(427) | aggressively releasing JDBC connection
      15/02 14:58:39 DEBUG - ConnectionManager.closeConnection(464) | releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
      15/02 14:58:39 DEBUG - Resources.getResource(109) | Loaded resource from context classloader: jar:file:/D:/RHDSWorkspaces/MCel/CSV2/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/CSV/WEB-INF/lib/jboss-seam-debug.jar!/META-INF/debug.xhtml
      15/02 14:58:39 DEBUG - SeamPhaseListener.begin(592) | beginning transaction prior to phase: RENDER_RESPONSE 6
      ....|






      from the logs, I see that hibernate flushes the entity, and the statements are executed. But nothing appears on my database.
      Can anybody give me a clue of what I am doing wrong?


      Regards,


      Fatih