1 Reply Latest reply on Jul 13, 2008 12:40 PM by faisal aziz

    Spring+JPA can not commit data.

    faisal aziz Newbie

      Spring 2.0.6
      JBoss 4.2.2 GA
      JDK 6

      persistence.xml

      <persistence-unit name="analytics" transaction-type="RESOURCE_LOCAL">
       <!--<jta-data-source>java:/@db.datasource.jndi@</jta-data-source>-->
       <non-jta-data-source>java:analyticsDS</non-jta-data-source>
       <properties>
       <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />
       <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider" />
       <property name="hibernate.use_second_level_cache" value="true" />
       <property name="hibernate.use_query_cache" value="true" />
       </properties>
       </persistence-unit>
      


      applicationContext.xml
       <import resource="jpaDaoContext.xml" />
       <import resource="servicesContext.xml" />
      
       <!-- Datasource configuration -->
       <bean id="loanaccounting-jpa-ds" class="org.springframework.jndi.JndiObjectFactoryBean">
       <property name="jndiName" value="java:comp/env/jdbc/analytics" />
       </bean>
      
       <!-- Entity Manager + JPA Configuration -->
       <bean id="entityManagerFactory"
       class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
       <property name="dataSource" ref="loanaccounting-jpa-ds" />
       <property name="persistenceUnitName" value="analytics" />
       <property name="jpaVendorAdapter">
       <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
       <property name="database" value="MYSQL"/>
       <property name="generateDdl" value="false"/>
       <property name="showSql" value="false" />
       </bean>
       </property>
       <property name="jpaPropertyMap">
       <props>
       <prop key="hibernate.cache.use_second_level_cache">true</prop>
       <prop key="hibernate.cache.use_query_cache">true</prop>
       <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
       <prop key="hibernate.jdbc.batch_size">50</prop>
       <prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml</prop>
       <prop key="hibernate.generate_statistics">true</prop>
       </props>
       </property>
       </bean>
      


      jpaContext.xml
      <!-- Transaction manager for a single JPA EntityManagerFactory (alternative to JTA) -->
       <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
       <property name="entityManagerFactory" ref="entityManagerFactory"/>
       </bean>
      
       <aop:config>
       <aop:pointcut id="serviceOperation"
       expression="execution(* com.primatics.analytics.service..*.*(..))"/>
       <aop:advisor pointcut-ref="serviceOperation" advice-ref="txAdvice"/>
       </aop:config>
      
       <tx:advice id="txAdvice" transaction-manager="transactionManager">
       <tx:attributes>
       <tx:method name="get*" read-only="true" propagation="SUPPORTS"/>
       <tx:method name="save*" read-only="false" propagation="REQUIRES_NEW"/>
       <tx:method name="update*" read-only="false" propagation="REQUIRES_NEW"/>
       <tx:method name="insert*" read-only="false" propagation="REQUIRES_NEW"/>
       <tx:method name="create*" read-only="false" propagation="REQUIRES_NEW"/>
       <tx:method name="persist*" read-only="false" propagation="REQUIRES_NEW"/>
       <tx:method name="delete*" read-only="false" propagation="REQUIRES_NEW"/>
       <tx:method name="remove*" read-only="false" propagation="REQUIRES_NEW"/>
       <tx:method name="register*" read-only="false" propagation="REQUIRES_NEW"/>
       </tx:attributes>
       </tx:advice>
      
       <!-- JPA annotations bean post processor.
       Will inject persistence related resources. -->
       <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
       <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
       <bean class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" />
      


      JBoss server.log snippet
      DEBUG [org.hibernate.engine.TwoPhaseLoad] resolving associations for [com.primatics.analytics.auth.UserStatus#VALIDATION_PENDING]
      DEBUG [org.hibernate.engine.TwoPhaseLoad] adding entity to second-level cache: [com.primatics.analytics.auth.UserStatus#VALIDATION_PENDING]
      DEBUG [org.hibernate.engine.TwoPhaseLoad] done materializing entity [com.primatics.analytics.auth.UserStatus#VALIDATION_PENDING]
      DEBUG [org.hibernate.engine.StatefulPersistenceContext] initializing non-lazy collections
      DEBUG [org.hibernate.event.def.AbstractSaveEventListener] delaying identity-insert due to no transaction in progress
      DEBUG [org.springframework.transaction.interceptor.TransactionInterceptor] Completing transaction for [com.primatics.analytics.service.admin.RegistrationService.createCustomer]
      DEBUG [org.springframework.orm.jpa.JpaTransactionManager] Triggering beforeCommit synchronization
      DEBUG [org.springframework.orm.jpa.JpaTransactionManager] Triggering beforeCompletion synchronization
      DEBUG [org.springframework.orm.jpa.JpaTransactionManager] Initiating transaction commit
      DEBUG [org.springframework.orm.jpa.JpaTransactionManager] Committing JPA transaction on EntityManager [org.hibernate.ejb.EntityManagerImpl@174689]
      DEBUG [org.hibernate.transaction.JDBCTransaction] commit
      DEBUG [org.hibernate.transaction.JDBCTransaction] re-enabling autocommit
      DEBUG [org.hibernate.transaction.JDBCTransaction] committed JDBC Connection
      DEBUG [org.hibernate.jdbc.ConnectionManager] aggressively releasing JDBC connection
      DEBUG [org.hibernate.jdbc.ConnectionManager] releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
      DEBUG [org.springframework.orm.jpa.JpaTransactionManager] Triggering afterCommit synchronization
      DEBUG [org.springframework.orm.jpa.JpaTransactionManager] Triggering afterCompletion synchronization
      DEBUG [org.springframework.transaction.support.TransactionSynchronizationManager] Clearing transaction synchronization
      


      It seems for some reason hiberate does not like the setup. Please help me out here.