Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

issue with commiting the transaction using 2 services call

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using spring data, with ms sql DB.
I am inserting the data into 2 table using the @Transactional annotation.
Calling 2 services from the single method for insertion in to 2(customer and address) tables.
In first service call data is getting commit in to customer table event though the another service call(address insertion call) is getting failed due to some exception.

logs as follows:-

EBUG - AbstractFlushingEventListener.logFlushResults(118) | Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
DEBUG - AbstractFlushingEventListener.logFlushResults(125) | Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
DEBUG - EntityPrinter.toString(114) | Listing entities:
DEBUG - EntityPrinter.toString(121) | customer{telephone1=212-752-1000, ext. 230, countryName=null, processKey=null, processStatus=0.........}
DEBUG - JdbcTransaction.doCommit(113) | committed JDBC Connection
DEBUG - JpaTransactionManager.doCleanupAfterCompletion(594) | Closing JPA EntityManager [org.hibernate.ejb.EntityManagerImpl@44581ea2] after transaction
DEBUG - EntityManagerFactoryUtils.closeEntityManager(338) | Closing JPA EntityManager
DEBUG - LogicalConnectionImpl.releaseConnection(232) | Releasing JDBC connection
DEBUG - LogicalConnectionImpl.releaseConnection(250) | Released JDBC connection
DEBUG - AbstractPlatformTransactionManager.cleanupAfterCompletion(1013) | Resuming suspended transaction after completion of inner transaction
DEBUG - AbstractBeanFactory.doGetBean(246) | Returning cached instance of singleton bean 'transactionManager'
DEBUG - AbstractPlatformTransactionManager.getTransaction(366) | Creating new transaction with name [org.springframework.data.jpa.repository.support.SimpleJpaRepository.save]: PROPAGATION_REQUIRED_NEW,ISOLATION_DEFAULT; ''
DEBUG - JpaTransactionManager.doBegin(369) | Opened new EntityManager [org.hibernate.ejb.EntityManagerImpl@53c7378f] for JPA transaction
DEBUG - AbstractTransactionImpl.begin(158) | begin
DEBUG - LogicalConnectionImpl.obtainConnection(212) | Obtaining JDBC connection
DEBUG - LogicalConnectionImpl.obtainConnection(218) | Obtained JDBC connection
DEBUG - JdbcTransaction.doBegin(69) | initial autocommit status: false
DEBUG - JpaTransactionManager.doBegin(408) | Not exposing JPA transaction [org.hibernate.ejb.EntityManagerImpl@53c7378f] as JDBC transaction because JpaDialect [org.springframework.orm.jpa.DefaultJpaDialect@6b04d3c8] does not support JDBC Connection retrieval
DEBUG - ActionQueue.addResolvedEntityInsertAction(213) | Executing identity-insert immediately
DEBUG - SqlExceptionHelper.logExceptions(139) | could not execute statement [n/a]


Using following configuration in method which is calling 2 services.

@Override
@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
public void transferData(Customer cutomer) {
custService.saveCutomer(customer);
addressService.addAddress(customer)

}

and my applicationContext configuration is.

<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="persistenceUnit"/>
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="com..."/>
</bean>
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
<property name="driverClassName" value="${gpIntDatabase.driverClassName}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="1800000"/>
<property name="numTestsPerEvictionRun" value="3"/>
<property name="minEvictableIdleTimeMillis" value="1800000"/>
<property name="validationQuery" value="SELECT 1"/>
</bean>

Any help would be appreciated.
Thanks in advance






 
dilip patidar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
using transaction annotation conf.
<tx:annotation-driven transaction-manager="transactionManager"/>
 
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using a Type II or Type IV driver ? What version is your driver ? Who published your driver ? AFAIK, the only Type IV drivers that work are Oracle and DB2. I am not aware of a Microsoft JDBC driver that supports coordinated transactions. You need an XA-aware transaction manager and support driver to that XA device which would route SQL through that device for your Spring framework to work the way you intend it to. Otherwise, you need to manually commit or rollback each (ie. not use the annotation).
 
Roger Sterling
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

dilip patidar wrote:using transaction annotation conf.
<tx:annotation-driven transaction-manager="transactionManager"/>



The MS SQLServer JDBC driver does not support XA transactions. What driver do you use ?
 
dilip patidar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Roger Sterling

We are not using XA transaction yet.
we have also tried driver to MS driver instead of jtds jdbc driver.
 
a wee bit from the empire
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic