2013年9月6日星期五

spring annotation configuration transaction is not rolled back

Members Great God There is now a demand


class AService {

public void ma () {]
mb ();
mc ();
mb ();
mc ();
}
private void mb () {}
private void mc () {}
}

need : mb and mc alone commit or rollback independently of each other mb or mc to be executed many times alone

how to configure this
------ Solution - -------------------------------------------
setting AOP


expression = "execution (public * com.xxx.controller. *. * (..))" />
limit which method to the transaction rollback

------ Solution - -------------------------------------------
is NEW_REQUIRED < br> ------ Solution ----------------------------------------- ---
look Affairs broadcast Settings
------ Solution ----------------------------- ---------------


Since you use Spring's transaction management will not use Try-catch up ;
In Spring If the business method is try-catch wrap, then this business method is free from Spring transaction management , and why ?
Because there will not be a try-catch any exceptions thrown from a business method , but was captured and eaten itself , leading to trigger an exception is thrown Spring transaction rollback policy is invalid !

------ Solution ------------------------------------ --------
remove the try catch can not be otherwise recognized framework .
------ For reference only -------------------------------------- -
which this method in a service in
require every once mb or mc must be submitted separately or rolled back once
how great God who is with ah thank
------ For reference only ------------------ ---------------------

---------------------- --------------------
not ah because I have these methods in the service of my ma () method added a catch out of the ma does not throw an exception ,
public void ma () {]
mb (); 1
mc (); 2
mb (); 3
mc (); 4
}
Even if one fails then a rollback ,
then run 2 . . . . That the results of each method will not affect other methods, can not throw out the ma abnormal
------ For reference only ---------- -----------------------------


save * "propagation =" REQUIRES_NEW "/>






---------------------------------------------- ------------------------------------
@ Service
public class TestServiceImpl implements ITestService {

@ Resource
private ITestDao routeDao;

@ Override
public boolean load () {
for (int i = 0; i <10; i + +) {
try {
saveA ();
} catch (Exception e) {
e.printStackTrace ();
}
}
}

@ Override
public void saveA () {
routeDao.saveA ();
}
}
---------------------------------------------- ---------------------------
Great God you look at my code problem in any place ?

Let saveA (); individuals can commit or rollback


------ For reference only ---------------------------------- -----
that means is that I deal with this cycle can not be placed in service in the business process layer processing only in the action ?
because this is part of the business logic layer I do not want to put action

for (int i = 0; i <10; i + +) {
try {
saveA ();
} catch (Exception e) {
e.printStackTrace ();
}
}

then there is no better way to solve it ?

Thank god above answer several

没有评论:

发表评论