PDA

View Full Version : problem during the declarative transaction


biju
Aug 19th, 2004, 07:58 AM
Hi,
I did changes as per the instruction but still i couldnt
do transaction rollback using declarative transaction.

My code is given below

TestSpringDao.java my dao class where i get the exception
--------------------------------------------------------------------

public String myQuery()throws DataAccessException {
String name = "";

try {
jt = new JdbcTemplate();
jt.setDataSource(dataSource);

jt.update("update retiredb set name='test12' where Id=1");
jt.update("insert into spring2 values ('test2','address2')");

}
catch (DataAccessException e)
{
System.out.println("inside exception DataAccessException ------" + e);
throw e;
}
catch (Exception ee) {
System.out.println("inside exception Exception ------" + ee);
}
return name;

my buisiness class from where i am calling the daos perticular method
-------------------------------------------------------------------------------

public boolean CreateRetirementDataObject(RetirementPlanBean rpb) {

try {
ts.myQuery();
}
catch (DataAccessException e)
{
System.out.println("inside DataAccessException buisiness class ------" + e);

}
catch (Exception e) {
System.out.println("inside exception in buisiness class<<<<<"+e);
}
return true;
}

and my xml files are look like this
----------------------------------------

<bean id="testSpring" class="beans.TestSpring">
<property name="dataSource"><ref local="dataSource"/></property>

</bean>

<bean id="retirementBusinessObject" class="beans.RetirementBusinessObject">
<property name="dataAccessObject"><ref local="testSpring"/></property>
</bean>
------------------------------------------------------------------------------


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

<bean id="senderNewTx" class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="target">
<ref bean="retirementBusinessObject"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED,-DataAccessException</prop>
</props>
</property>
</bean>

how can i overcome the problem?
is there any mistakes using the transaction setting done by me?

Thanking you,
Biju

Rod Johnson
Aug 19th, 2004, 08:02 AM
You're still swallowing in the second Exception catch block.

Please post a reply to an existing thread, rather than create a new thread in the forum.

biju
Aug 19th, 2004, 10:24 AM
Hi,
thak u very much for ur earlier responses

But still i have the problem.
I want to inform u that i am using the MSACESS database
will this create any problem?
my code look as below now


TestSpringDao.java my dao class where i get the exception
--------------------------------------------------------------------

public String myQuery()throws Exception,DataAccessException {
String name = "";

try {
jt = new JdbcTemplate();
jt.setDataSource(dataSource);

jt.update("update retiredb set name='test12' where Id=1");
jt.update("insert into spring2 values ('test2','address2')");

}
catch (DataAccessException e)
{
System.out.println("inside exception DataAccessException ------" + e);
throw e;
}
catch (Exception ee) {
System.out.println("inside exception Exception ------" + ee);
throw ee;

}
return name;

my buisiness class from where i am calling the daos perticular method
-------------------------------------------------------------------------------

public boolean CreateRetirementDataObject(RetirementPlanBean rpb) {

try {
ts.myQuery();
}
catch (DataAccessException e)
{
System.out.println("inside DataAccessException buisiness class ------" + e);

}
catch (Exception e) {
System.out.println("inside exception in buisiness class<<<<<"+e);
}
return true;
}

and my xml files are look like this
----------------------------------------

<bean id="testSpring" class="beans.TestSpring">
<property name="dataSource"><ref local="dataSource"/></property>

</bean>

<bean id="retirementBusinessObject" class="beans.RetirementBusinessObject">
<property name="dataAccessObject"><ref local="testSpring"/></property>
</bean>
------------------------------------------------------------------------------


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

<bean id="senderNewTx" class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="target">
<ref bean="retirementBusinessObject"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED,-DataAccessException,-Exception</prop>
</props>
</property>
</bean>

I am getting the exception in catch block of DataAccessException .
Is there is any problem in setting the target for transaction.
and what actualy the property key "*" means(Is it all the method of that perticular object)

Thanking you,
Biju

Colin Sampaleanu
Aug 19th, 2004, 11:36 AM
Your business class is still swallowing the DataAccessException.

The "*" is just a generic regex which will match all methods.

Regards,

biju
Aug 19th, 2004, 12:54 PM
Hi,
thak u very much for ur earlier responses
As per ur advice i re thrown the exception i am catching in buisiness class
to the action class.
But still i have the problem.
I want to inform u that i am using the MSACESS database will this create any problem?
my code look as below now


TestSpringDao.java my dao class where i get the exception
--------------------------------------------------------------------

public String myQuery()throws Exception,DataAccessException {
String name = "";

try {
jt = new JdbcTemplate();
jt.setDataSource(dataSource);

jt.update("update retiredb set name='test12' where Id=1");
jt.update("insert into spring2 values ('test2','address2')");

}
catch (DataAccessException e)
{
System.out.println("inside exception DataAccessException ------" + e);
throw e;
}
catch (Exception ee) {
System.out.println("inside exception Exception ------" + ee);
throw ee;

}
return name;

my buisiness class from where i am calling the daos perticular method
-------------------------------------------------------------------------------

public boolean CreateRetirementDataObject(RetirementPlanBean rpb)throws Exception,DataAccessException {

try {
ts.myQuery();
}
catch (DataAccessException e)
{
System.out.println("inside DataAccessException buisiness class ------" + e);
throw e;

}
catch (Exception e) {
System.out.println("inside exception in buisiness class<<<<<"+e);
throw e;

}
return true;
}

and my xml files are look like this
----------------------------------------

<bean id="testSpring" class="beans.TestSpring">
<property name="dataSource"><ref local="dataSource"/></property>

</bean>

<bean id="retirementBusinessObject" class="beans.RetirementBusinessObject">
<property name="dataAccessObject"><ref local="testSpring"/></property>
</bean>
------------------------------------------------------------------------------


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

<bean id="senderNewTx" class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="target">
<ref bean="retirementBusinessObject"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED,-DataAccessException,-Exception</prop>
</props>
</property>
</bean>

I am getting the exception in catch block of DataAccessException .

Is there is any problem in setting the target for transaction.
what should be the target class which is specifying?
whether It should be the buisiness class from where i am calling the dao method?

Thanking you,
Biju

Colin Sampaleanu
Aug 19th, 2004, 03:30 PM
You should be wrapping the business method.

The best way to get a handle on what is going on is to look at your log. If your catch block in the business method is catching the error, and then rethrowing it, then the transaction should be reacting to that, and the log should show the rollback (or commit, if in fact it's not rolling back, or neither, if in fact you are not even in a transaction).

Regards,

biju
Aug 20th, 2004, 01:09 AM
Hi ,
U mean the method may not be in transaction?
than what setting i should do to include a method in a transaction?

The server is not showing any message regarding the transaction except "transactionManager" singleton object is created...

Thanking you,
Biju

Colin Sampaleanu
Aug 20th, 2004, 09:41 AM
Are you sure you're using the business object through the proxy, which you have called 'senderNewTx', and not directly as the unwrapped business object itself, which you call 'retirementBusinessObject'?

Normally, if you create wrap a n object transactionally, it's a good idea to use some sort of convention in naming, such as
adding 'Target' to the name of the raw object to be wrapped, and the simple name for the wrapped version, i.e.
myServiceTarget - this is the raw object
myService - this is the same thing wrapped with the proxy factory bean

The manual in this section:
http://www.springframework.org/docs/reference/aop.html#aop-concise-proxy
describes how to wrap target objects as an inner bean, so you can't accidentally use the unwrapped object.

Regards,