ServiceMix/蓝图/JPA 集成 [英] ServiceMix / Blueprint / JPA Integration

查看:18
本文介绍了ServiceMix/蓝图/JPA 集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一周的时间尝试将 JPA/ServiceMix 4.5.1/camel-jpa 2.10.4/Blueprint 集成在一起.我目前正在使用 OpenJPA,但并没有与之绑定.servicemix使用的aries jpa版本为0.3.0.

I have been spending the week attempting to integrate JPA / ServiceMix 4.5.1 / camel-jpa 2.10.4 / Blueprint together. I'm currently using OpenJPA, but am not tied to it. The version of aries jpa used by servicemix is 0.3.0.

我无法通过的堆栈跟踪是:

The stack trace I cannot get past is:

org.osgi.service.blueprint.container.ComponentDefinitionException: Error when instanciating bean workoutEntity of class class [...].WorkoutEntity
at org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:271)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:708)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:64)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.di.RefRecipe.internalCreate(RefRecipe.java:60)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:64)[10:org.apache.aries.blueprint:0.3.2]
at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:219)[10:org.apache.aries.blueprint:0.3.2]
[...]
Caused by: <openjpa-2.2.0-r422266:1244990 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: [javax.sql.DataSource]
at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:218)
at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)

[...]
Caused by: java.lang.IllegalArgumentException: [javax.sql.DataSource]
at org.apache.aries.jndi.services.ServiceHelper.proxyPriviledged(ServiceHelper.java:348)
at org.apache.aries.jndi.services.ServiceHelper.access$700(ServiceHelper.java:65)
at org.apache.aries.jndi.services.ServiceHelper$1.run(ServiceHelper.java:285)
at java.security.AccessController.doPrivileged(Native Method)[:1.6.0_43]
[...]

我尝试了几种变体.这是我当前的配置:

I've attempted several variations. Here is my current configuration:

持久性.xml:

<persistence-unit name="customer1" transaction-type="JTA">
     <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
     <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/prototypedb)</jta-data-source>
     <class>...</class>
</persistence-unit>

骆驼上下文.xml

<service id="PrototypeDB" interface="javax.sql.DataSource">
    <service-properties>
        <entry key="osgi.jndi.service.name" value="jdbc/prototypedb"/>
    </service-properties>
    <bean class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName"        value="com.mysql.jdbc.Driver"/>
        <property name="url"                    value="jdbc:mysql://localhost:3306/prototype"/>
        <property name="username"               value="root"/>
        <property name="password"               value="..."/>
    </bean>
</service>

<service ref="workoutEntity" interface="..."/>
<bean id="workoutEntity" class="...">
    <jpa:unit index="0"         unitname="customer1" />
    <tx:transaction method="*"  value="Required"/>
</bean>

实体 Bean(用 groovy 编写)

Entity Bean (written in groovy)

@Entity
@Table(name='customer1')
@Slf4j
class WorkoutEntity implements IWorkoutEntity{

    private EntityManager entityManager

    WorkoutEntity(final EntityManagerFactory entityManagerFactory) {
        this.entityManager = entityManagerFactory.createEntityManager()
    }

    @Handler
    void create( @Body final String input) {
         // ...
    }
}

我尝试了多种不同的数据源实现,包括 BasicDataSource、org.springframework.jdbc.datasource.SimpleDriverDataSource 和 com.mysql.jdbc.jdbc2.optional.MysqlDataSource.都会导致 IllegalArgumentException.

I've attempted multiple different implementations of a DataSource, including the BasicDataSource, org.springframework.jdbc.datasource.SimpleDriverDataSource, and com.mysql.jdbc.jdbc2.optional.MysqlDataSource. All cause the IllegalArgumentException.

我还尝试放弃使用 JNDI,而是直接在 persistence.xml 中定义数据源.这会导致 OpenJPA 包中的 ClassNotFoundException,因为它没有导入 mysql 驱动程序.我更喜欢在我的 camel-context.xml 中定义它,并且不想重新捆绑 OpenJPA jar.

I've also attempted to forego using JNDI and instead define the data source directly in the persistence.xml. This causes ClassNotFoundException in the OpenJPA bundle, as it is not importing the mysql driver. I'd prefer to define this in my camel-context.xml and would prefer to not re-bundle the OpenJPA jar.

推荐答案

您可能还需要安装 aries JNDI 功能.这有助于通过 JNDI 查找调用 OSGi 服务.这应该是缺失的部分.

You probably also need the aries JNDI features installed. This helps to call OSGi services via JNDI lookups. This should be the missing piece.

这篇关于ServiceMix/蓝图/JPA 集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆