简体   繁体   English

为什么回滚不适用于hibernate / osgi / karaf / JPA / mysql

[英]Why does rollback not work with hibernate/osgi/karaf/JPA/mysql

I am using karaf 3.0.3 and the following Hibernate bundles: 我正在使用karaf 3.0.3和以下Hibernate捆绑软件:

161 | 161 | Active | 活跃 80 | 80 | 4.2.12.Final | 4.2.12。最后| hibernate-core 休眠核心
162 | 162 | Active | 活跃 80 | 80 | 4.2.12.Final | 4.2.12。最后| hibernate-entitymanager 冬眠-的EntityManager
172 | 172 | Active | 活跃 80 | 80 | 4.2.12.Final | 4.2.12。最后| hibernate-osgi 冬眠OSGi的

With this set-up I cannot get a transaction roll-back to work, although I can deploy the exact same components (JPA DAOs, service layer etc) as a standalone Spring application, and I see roll-backs performed correctly. 通过这种设置,尽管我可以部署与独立的Spring应用程序完全相同的组件(JPA DAO,服务层等),但我无法使事务回滚正常工作,并且我看到回滚已正确执行。

What are the gotchas when trying to get transactions to work successfully with OSGI/hibernate? 尝试使事务与OSGI /休眠一起成功运行时的陷阱是什么?

  • is it something to do with cross-bundle transactions? 与跨捆绑交易有关吗? (My DAOs and service layer are in separate bundles) (我的DAO和服务层在单独的捆绑包中)

If I get not replies here, I will update with more specific information, but first I want to see if this is a common problem with OSGi/hibernate/jpa. 如果在这里没有得到答复,我将提供更多具体信息,但首先,我想看看这是否是OSGi / hibernate / jpa的常见问题。

edit after user2007829's comment: The DAOs extend Spring's JpaRepository , and the service layer method is annotated with Spring's @Transactional . 在user2007829的注释之后进行编辑: DAO扩展了Spring的JpaRepository ,并且服务层方法由Spring的@Transactional注释。 I believe in this setup, auto commit should be implicitly off, and the standalone spring app set-up is working as expected. 我相信在此设置中,应该自动关闭自动提交,并且独立的spring应用程序设置可以按预期运行。 Is that wrong? 错了吗

How should the persistence unit XML file differ in the OSGI case? 持久性单元XML文件在OSGI情况下应如何区别? Right now the only difference is that the transaction-type is JTA in the karaf case, and I have a declaration like this: 现在唯一的区别是在karaf情况下,事务类型为JTA,我有一个这样的声明:

<jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/‌​my-datasource)</jta-data-source>

There are many possible reasons why this could occur. 发生这种情况的原因可能有很多。 For example your data source might not wrap an XADataSource correctly. 例如,您的数据源可能未正确包装XADataSource。 In this case it can occur that the EntityManager did not join the transaction or is not enlisted as XA ressource. 在这种情况下,可能会出现EntityManager未加入事务或未被登记为XA资源的情况。

Have a look at these tutorials. 看看这些教程。 It is easier to start from a working basis: http://www.liquid-reality.de/x/LYBk http://www.liquid-reality.de/x/C4DK 从工作基础开始比较容易: http : //www.liquid-reality.de/x/LYBk http://www.liquid-reality.de/x/C4DK

Unfortunately the tutorials are based on blueprint and aries jpa so it is not exactly spring. 不幸的是,这些教程是基于蓝图和白羊座jpa的,因此这并不是完全正确的。 You still should be able to use some of the informations. 您仍然应该能够使用某些信息。 Additionally I can only recommend to switch from spring to blueprint as spring does not support OSGi anymore. 另外,由于spring不再支持OSGi,我只建议从spring切换到blueprint。

For blueprint there are apache aries which the tutorials are based on or eclipse gemini. 对于蓝图,有基于本教程的apache aries或使双子座eclipse。

And how do you use the hibernate? 以及如何使用休眠模式? Do you create a transaction and work within it or are your queries session related? 您是否创建交易并在其中进行交易,或者您的查询会话相关? Also, did you set autocommit to false? 另外,您是否将autocommit设置为false?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM