简体   繁体   English

如何在Spring和EJB中使用同一事务?

[英]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.

相关问题 如何在ejb中获得方法级别的事务超时? - How can i get method level transaction time out in ejb? 如何使用Spring HibernateOperations对隐式事务进行简单操作? - How can I use Spring HibernateOperations for simple operations with a implicit transaction? 如何在EJB中设置事务隔离? - How do i set the Transaction Isolation in EJB? 当我添加ejb模块时,Spring事务停止工作 - Spring transaction stops to work when i add ejb module 在Spring数据JPA的同一笔交易中看不到修改,为什么在同一笔交易中修改后却为空? - the modifying can not be visible in the same transaction in spring data jpa,why i got null after modifying in the same transaction? EJB 3,同一bean中的事务流 - EJB 3, Transaction flow in same bean 如何在EJB中提交事务? - how to commit a transaction in EJB? 如何在Spring Boot中通过jdbcTemplate将单个事务与多个数据源一起使用? - How can I use single transaction with multiple datasources with jdbcTemplate in spring boot? 我什么时候应该使用EJB事务属性&#39;Mandatory&#39;和&#39;Never&#39; - When should I use EJB transaction attributes 'Mandatory' and 'Never' 如何测试使用企业应用程序的EJB模块 - How can I test EJB module that use an Enterprise Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM