0

I need step by step guide to handle transactions in spring sqltemplate. Transaction handling has to be implemented in my project. Guide me. Need to use the transaction Managment with SqlTemplate.

Dan
  • 10,990
  • 7
  • 51
  • 80
minil
  • 6,895
  • 16
  • 48
  • 55
  • What is SqlTemplate? Do you mean Cayenne? If so here's an article on that: https://cwiki.apache.org/CAY/spring-integration-examples.html – Dan May 02 '11 at 01:03

2 Answers2

1

I suggest you use @Transaction annotation than code it manually. You may follow example here. For its best practice, you may read here. If you plan to spend few hours to study Spring Data JPA, you almost no need to handle transaction manually for most cases.

Thanks.

Community
  • 1
  • 1
Lee Chee Kiam
  • 11,450
  • 10
  • 65
  • 87
0

if you are using Programmatic Transactions then use below

<bean id="transactionManager"   class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
    <ref local="dataSource"/>
</property>
</bean>

Programmatic means you have transaction management code surrounding your business code. This gives extreme flexibility, but is difficult to maintain. Declarative means you separate transaction management from the business code. You can use annotations or XML based configuration.

Declarative Transaction Management allows to eliminate any dependencies on the transaction framework from the Java code. The four participants to provide the transaction support are transaction manager, proxy factory, transaction interceptor, and a set of transaction attributes. below is an example

<bean id="boxOffice" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager"><ref bean="transactionManager"/></property>
<property name="target">
    <ref bean="boxOfficeService"/>
</property>
<property name="transactionAttributes">
    <props>
        <prop key="get*">PROPAGATION_SUPPORTS,readOnly</prop>
        <prop key="allocate*">PROPAGATION_REQUIRED</prop>
    </props>
</property>
</bean>
kapil das
  • 2,061
  • 1
  • 28
  • 29