Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 事务回滚时如何返回不同的值?_Java_Spring_Ssh_Transactions - Fatal编程技术网

Java 事务回滚时如何返回不同的值?

Java 事务回滚时如何返回不同的值?,java,spring,ssh,transactions,Java,Spring,Ssh,Transactions,我使用ssh框架来开发web应用程序 这里有一个我的交易的例子 @Transactional public StudentEntity addStudent(StudentEntity studentEntity) { return studentDAO.save(studentEntity); } 现在,我想在抛出异常时返回null,然后执行事务回滚。要以编程方式回滚事务,请查看TransactionSpectSupport类 @Transactional public Stu

我使用ssh框架来开发web应用程序

这里有一个我的交易的例子

@Transactional
public StudentEntity addStudent(StudentEntity studentEntity) {
       return studentDAO.save(studentEntity);
}

现在,我想在抛出异常时返回null,然后执行事务回滚。

要以编程方式回滚事务,请查看
TransactionSpectSupport

@Transactional
public StudentEntity addStudent(StudentEntity studentEntity) {
      try {
       return studentDAO.save(studentEntity);
        }
      catch(Exception ex) {
       //set transaction for rollback.
      TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
     }
}
你可以用声明的方式来做

@Transactional(rollbackFor={SomeSpecificException.class, SomeOtherSpecificException.class}) 

要以编程方式回滚事务,请查看
transactionspectsupport

@Transactional
public StudentEntity addStudent(StudentEntity studentEntity) {
      try {
       return studentDAO.save(studentEntity);
        }
      catch(Exception ex) {
       //set transaction for rollback.
      TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
     }
}
你可以用声明的方式来做

@Transactional(rollbackFor={SomeSpecificException.class, SomeOtherSpecificException.class}) 

要以编程方式回滚事务,请查看
transactionspectsupport

@Transactional
public StudentEntity addStudent(StudentEntity studentEntity) {
      try {
       return studentDAO.save(studentEntity);
        }
      catch(Exception ex) {
       //set transaction for rollback.
      TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
     }
}
你可以用声明的方式来做

@Transactional(rollbackFor={SomeSpecificException.class, SomeOtherSpecificException.class}) 

要以编程方式回滚事务,请查看
transactionspectsupport

@Transactional
public StudentEntity addStudent(StudentEntity studentEntity) {
      try {
       return studentDAO.save(studentEntity);
        }
      catch(Exception ex) {
       //set transaction for rollback.
      TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
     }
}
你可以用声明的方式来做

@Transactional(rollbackFor={SomeSpecificException.class, SomeOtherSpecificException.class}) 

通常不建议返回
null

如果您预期逻辑中会出现任何
异常
,则应通过
throws
子句通知调用方,以便他们为此类场景做好准备

关于回滚,您应该考虑下面的更新到您的代码> @事务性< /COD>注释< /P>

@Transactional(rollbackFor=Exception.class)

请注意,这将在抛出任何异常后回滚事务。

通常不建议返回
null

如果您预期逻辑中会出现任何
异常
,则应通过
throws
子句通知调用方,以便他们为此类场景做好准备

关于回滚,您应该考虑下面的更新到您的代码> @事务性< /COD>注释< /P>

@Transactional(rollbackFor=Exception.class)

请注意,这将在抛出任何异常后回滚事务。

通常不建议返回
null

如果您预期逻辑中会出现任何
异常
,则应通过
throws
子句通知调用方,以便他们为此类场景做好准备

关于回滚,您应该考虑下面的更新到您的代码> @事务性< /COD>注释< /P>

@Transactional(rollbackFor=Exception.class)

请注意,这将在抛出任何异常后回滚事务。

通常不建议返回
null

如果您预期逻辑中会出现任何
异常
,则应通过
throws
子句通知调用方,以便他们为此类场景做好准备

关于回滚,您应该考虑下面的更新到您的代码> @事务性< /COD>注释< /P>

@Transactional(rollbackFor=Exception.class)

请注意,这将在抛出任何异常后回滚事务。

或者我应该从事务中捕获异常,而不是更改返回值?或者我应该从事务中捕获异常,而不是更改返回值?或者我应该从事务中捕获异常,如果我添加@Transactional(rollboor=Exception.class),异常是否仍然从方法中抛出?或者是否被事务捕获?它将被抛出。有关回滚的更多详细信息,请阅读。如果我添加@Transactional(rollboor=Exception.class),异常是否仍然从方法中抛出?或者是否被事务捕获?它将被抛出。有关回滚的更多详细信息,请阅读。如果我添加@Transactional(rollboor=Exception.class),异常是否仍然从方法中抛出?或者是否被事务捕获?它将被抛出。有关回滚的更多详细信息,请阅读。如果我添加@Transactional(rollboor=Exception.class),异常是否仍然从方法中抛出?或者是否被事务捕获?它将被抛出。有关回滚的详细信息,请务必阅读。