交易无效。春季启动@Transactional

时间:2017-05-05 16:56:13

标签: spring hibernate jpa transactions

@Component
public class MyComponent {
    @Autowired
    private MyService myService;

    @Transactional
    public boolean processStream(InputStream is) {
        ...
        myService.doIt(foo);
        ...
    }
}

@Service
public class MyServiceImpl implements MyService {
    @PersistenceContext
    private EntityManager em;

    @Transactional
    public Lei doIt(Foo foo) {
        ...
        foo = em.merge(foo);
        ...
    }
}

我的问题是,在处理流时,Foo对象已经提交到数据库。我希望在processStream完成时提交它。

1 个答案:

答案 0 :(得分:0)

得到它:MyComponent :: processStream()是从MyComponent :: processFile()调用的

似乎在ENTRY METHOD

上需要@Transactional注释

这有助于调试: logging.level.org.springframework.transaction.interceptor = TRACE