cktechnical
Monday, October 18, 2004
 
The following was ripped from the spring-reference.pdf available on the www.springframework.org website. The purpose of this blog entry is simply to remind myself what the properties are for transactions when defining them within the applicationContext.xml file.

I also wanted to give myself some examples from actual running code, in this case, from the JPetstore Sample Application provided by Spring.

The TransactionDefinition interface specifies:

• Transaction isolation: The degree of isolation this transaction has from the work of other transactions. For

example, can this transaction see uncommitted writes from other transactions?

• Transaction propagation: Normally all code executed within a transaction scope will run in that

transaction. However, there are several options specificying behaviour if a transactional method is executed

when a transaction context already exists: For example, simply running in the existing transaction (the most

common case); or suspending the existing transaction and creating a new transaction. Spring offers the

transaction propagation options familiar from EJB CMT.

• Transaction timeout: How long this transaction may run before timing out (automatically being rolled

back by the underlying transaction infrastructure).

• Read-only status: A read-only transaction does not modify any data. Read-only transactions can be a

useful optimization in some cases (such as when using Hibernate).


<!-- - A parent bean definition which is a base definition for transaction proxies. - It is markes as abstract, since it is never supposed to be instantiated itself. - We set shared transaction attributes here, following our naming patterns. - The attributes can still be overridden in child bean definitions. -->



<bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">

<property name="transactionManager"><ref bean="transactionManager"></ref>

<property name="transactionAttributes">

<props>

<prop key="insert*">PROPAGATION_REQUIRED</prop>

<prop key="update*">PROPAGATION_REQUIRED</prop>

<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>

</props>

</property>

</property>


<bean id="petStore" parent="baseTransactionProxy">

<property name="target">

<bean class="org.springframework.samples.jpetstore.domain.logic.PetStoreImpl">

<property name="accountDao"><ref bean="accountDao"/></property>

<property name="categoryDao"><ref bean="categoryDao"/></property>

<property name="productDao"><ref bean="productDao"/></property>

<property name="itemDao"><ref bean="itemDao"/></property>

<property name="orderDao"><ref bean="orderDao"/></property>

</bean>

</property>


Comments: Post a Comment

<< Home

Powered by Blogger