How to rollback the transaction while spring controller has runtime exception...
i found some snippet from google i.e,
@Transactional(rollBackFor = Exception.class)
I think this only applicable for service class has the exception.
I need to rollback controller class has any exception.
forexample
@controller
public class test1
{
public void testing()
{
try
{
test2.sampletrans()
int k=5/0; // what i do from here i got exception
}
catch(Exception e)
{
}
}
@Service
@Transactional(rollBackFor = Exception.class)
public class test2
{
public void sampletrans()
{
try
{
sessionfactor.getCurrentSession.createSQLquery("update test set a=5");
int k=5/0; // if i has any exception from here. i think it will be automatically rollback.
}
catch(Exception e)
{
}
}