[英]How can I use the same transaction in Spring and an EJB?
I have no development experience with Spring, since we're a Java EE shop. 我没有Java开发经验,因为我们是Java EE商店。 However, we are looking into a solution for our needs that runs on Spring and should integrate our existing Java EE solution.
但是,我们正在寻找能够在Spring上运行的解决方案,并且应该集成我们现有的Java EE解决方案。
After reading the Spring 3.0.5 documentation, I'm still uncertain how a transaction can be propagated from Spring to an EJB. 在阅读Spring 3.0.5文档之后,我仍然不确定如何将事务从Spring传播到EJB。
For instance, a Spring bean would create a transaction, save some stuff into one database and then hand over the transaction to one of our stateless session beans, which (using JPA) saves some other stuff into another database. 例如,Spring bean会创建一个事务,将一些东西保存到一个数据库中,然后将事务移交给我们的无状态会话bean之一,后者(使用JPA)将其他东西保存到另一个数据库中。 And all of this must run under the same transaction, which is committed when the control is returned to the Spring bean.
所有这些都必须在同一事务下运行,该事务在控件返回到Spring bean时提交。
Also, I'm not clear about the deployment: Would Spring run as a webapp in the EAR that contains the session beans? 另外,我不清楚部署情况:Spring是否可以在包含会话bean的EAR中作为webapp运行?
if you configure Spring to use a JTATransactionManager and then call your SessionBean from within Spring the bean should actually pick up the Spring-created transaction. 如果将Spring配置为使用JTATransactionManager,然后从Spring内部调用SessionBean,则bean实际上应该接管Spring创建的事务。 Have look here: http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#transaction-application-server-integration and the described
<tx:jta-transaction-manager/>
在这里查看: http : //static.springsource.org/spring/docs/3.1.x/spring-framework-reference/htmlsingle/spring-framework-reference.html#transaction-application-server-integration和描述的
<tx:jta-transaction-manager/>
I actually only did it the other way around (joining EJB Transaction in spring) so I'm not completely sure, but you can easily test it by setting 实际上,我只是以相反的方式(在春季加入EJB事务)进行了此操作,因此我不确定,但是您可以通过设置轻松地对其进行测试
@TransactionAttribute(TransactionAttributeType.MANDATORY)
on your SessionBean and call it from spring... if there's not existing Transaction you will end up with a TransactionRequiredException
在您的SessionBean上并从春季开始调用...如果不存在Transaction,则最终会产生
TransactionRequiredException
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.