Java 要求_NEW在spring中不创建新事务+;冬眠

Java 要求_NEW在spring中不创建新事务+;冬眠,java,hibernate,spring-transactions,Java,Hibernate,Spring Transactions,我有一个Spring和hibernate应用程序(都是最新版本),我有两个bean,如下所述 @Component public class Bean1{ @Autowired Bean2 bean2; @Transactional(propagation = Propagation.REQUIRED) public void foo() { bean2.bar(); } @Component public class Bean2{ @Transactional(propag

我有一个Spring和hibernate应用程序(都是最新版本),我有两个bean,如下所述

@Component
public class Bean1{

@Autowired 
Bean2 bean2;

@Transactional(propagation = Propagation.REQUIRED)
public void foo()
{
    bean2.bar();
}


@Component
public class Bean2{

@Transactional(propagation = Propagation.REQUIRES_NEW)
public void bar()
{
    try{
           // Do something which throws exception
    }
    catch (Exception e) {
        log & eat the exception here only.
        But inspite of this the outer transaciton gets rolled back
    }
}
问题是,当
bean2.bar
导致任何异常(例如,外部
Key ConstraintViolationException
)时,它回滚外部事务,并说“事务回滚,因为它已标记为仅回滚”,“moreInfo”:“}”

在查看hibernate日志时,我只找到了一行“新事务”

这意味着没有为内部
bean2.bar();


我无法找出这里有什么问题?非常感谢您的帮助。

需要\u新的仅适用于JTA事务管理器。 参考Spring文档

需要新的
公共静态最终传播需要\u NEW

以非事务性方式执行,如果需要,则暂停当前事务 存在。类似于同名的EJB事务属性。
注意: 实际的交易暂停将不会在所有系统上开箱即用 事务管理器。这尤其适用于 JtaTransactionManager,它需要 javax.transaction.TransactionManager将提供给it部门 (在标准J2EE中是特定于服务器的)

D| o.s.o.h.HibernateTransactionManager- Creating new transaction with name ... PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''