简体   繁体   English

OSGi包之间的OpenJPA持久性

[英]OpenJPA persistence between OSGi bundles

I have two OSGi bundles deployed on Apache Karaf container. 我在Apache Karaf容器上部署了两个OSGi捆绑软件。 Lets say they are A and B. The A bundle is the main bundle which contains all database entities and persistence logic. 可以说它们是A和B。A包是包含所有数据库实体和持久性逻辑的主要包。 The B OSGi bundle is an application which uses methods from A to store some data into database. B OSGi软件包是一个应用程序,它使用A中的方法将一些数据存储到数据库中。 Also bundle B has CXF web service endpoint. 捆绑软件B也具有CXF Web服务端点。 The persistence is handled by OpenJPA . 持久性由OpenJPA处理。

Method in bundle A wraps the persist method of entity manager. 捆绑软件A中的方法包装了实体管理器的persist方法。 In bundle B there is a method which takes an object as a parameter which is defined in bundle A and has the method to persist data. 在捆绑软件B中,有一种方法将对象作为参数,该对象在捆绑软件A中定义,并且具有持久化数据的方法。 When I call that method in bundle B, all is ok, the data is persisted into database as expected. 当我在捆绑软件B中调用该方法时,一切正常,数据将按预期方式保存到数据库中。

The problem is that I want to update the an entity in B bundle's CXF endpoint implementation class which is exposed as a Spring bean and has OSGi reference to an object from bundle A which contains find statement to find the entity I need to update. 问题是我想更新B捆绑软件的CXF终结点实现类中的一个实体,该类作为Spring bean公开,并且OSGi引用了捆绑软件A中的对象,该对象包含find语句以查找我需要更新的实体。

The entity is returned to me correctly when I invoke find method, but when I set some new value the transaction does not get committed and the data does not appears in the database. 当我调用find方法时,该实体会正确返回给我,但是当我设置一些新值时,事务不会被提交,数据也不会出现在数据库中。

As I know one of OpenJPA features is that when you call persist to an object, then later you can set some new data to it and the needed transactions are made to update that entity. 据我所知, OpenJPA功能之一是,当您对某个对象调用持久化时,随后您可以为其设置一些新数据,并进行必要的事务以更新该实体。 It does not seem to be working in my case. 在我看来,它似乎不起作用。 I have tried to annotate CXF endpoint implementation class with org.springframework.transaction.annotation.Transactional annotation. 我尝试使用org.springframework.transaction.annotation.Transactional注释对CXF端点实现类进行注释。 But this is not working as well. 但这不是很好。

Maybe someone know where might be the problem? 也许有人知道问题出在哪里? Do I need to write query which updates my entity in CXF endpoint? 我是否需要编写查询来更新CXF端点中的实体?

In this case I suggest switching from spring to blueprint. 在这种情况下,我建议从春季切换到蓝图。 If you take a look at aries blueprint (for example) which is used by Karaf you are able to retrieve for example DAOs from Bundle A, call a "changing method" from Bundle B and it'll persisted by the Transaction Manager attached to Bundle A. 如果查看一下Karaf使用的白羊星座蓝图(例如),则可以从捆绑软件A中检索DAO,例如从捆绑软件B中调用“更改方法”,并将其附加到捆绑软件中的Transaction Manager中一种。

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

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