PDA

View Full Version : Transaction attributes



DANLZ
Jul 26th, 2006, 06:44 AM
Hello.
I have a problem with tansaction attributes.
Configuration is:

<bean id="aBean" parent="txProxyTemplate">
<property name="target">
<bean class="pl.siemens.ptdbos.service.data.billing.download.Bi llingDataImportUtil">
</bean>
</property>
<property name="transactionAttributes">
<props>
<prop key="inner">PROPAGATION_REQUIRES_NEW,-Exception</prop>
<prop key="outer">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>


Then in aBean class I do this:

public void outer() {
try {
this.inner();
} catch (Exception e) {
// put info to log
}
}

The problem is that transaction attributes for inner() method do not work.
No new transaction is created.

What am I missing?

Thanks in advance

Colin Yates
Jul 26th, 2006, 06:55 AM
The problem is that there are two objects involved, your code and the proxy which implements the transactions.

Because the transaction is a JDK proxy and not a subclass when you call this.inner() you are bypassing the "outer" proxy and calling a method directory on your class.

There are a number of workarounds (exposing the proxy via threadLocal, injecting the proxy onto your self/using the methodInjectingFactoryBean) but none of these are particularly elegant and it is best if you can avoid it.

DANLZ
Jul 26th, 2006, 07:15 AM
There are a number of workarounds (exposing the proxy via threadLocal, injecting the proxy onto your self/using the methodInjectingFactoryBean) but none of these are particularly elegant and it is best if you can avoid it.

I've moved inner() method to another bean and it works.
But this adds unnecessary bean (only 1 method).

Thanks anyway