Why does not commit transaction of Requires_New?

断了今生、忘了曾经 提交于 2019-12-06 09:05:57

You have to initialize another TestTransactionLocal with a use of SessionContext#getBusinessObject method. This way your TestTransactionLocal instance will respect @TransactionAttribute annotation.

@Resource
private SessionContext sessionContext;

private TestTransactionLocal local;

@PostConstruct
void init() {
    local = sessionContext.getBusinessObject(TestTransactionLocal.class);
}

Then invoke insertObject() through this new reference:

local.insertObject(i);

See this blog post: http://www.adam-bien.com/roller/abien/entry/how_to_self_invoke_ejb

You're calling prepare() method directly, so the transaction annotation isn't considered. You would need to call it through its own interface i.e. myTestTimerLocal.prepare(), for any transactional effect.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!