2017-05-05 69 views
0
@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完成时它会被提交。交易不起作用。春季启动@Transactional

+0

即使使用spring.jpa.properties.org.hibernate.flushMode = MANUAL,Foo对象仍可立即显示 – ropo

回答

0

明白了:MyComponent的:: processStream()从MyComponent的:: processFile(被称为)

看来,@Transactional注解需要在输入法

这有助于调试: 记录。 level.org.springframework.transaction.interceptor = TRACE