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

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

问题描述

我已经花了一周试图JPA /集成的ServiceMix 4.5.1 /骆驼JPA 2.10.4 /蓝图在一起。我目前使用OpenJPA的,但我不依赖于它。由ServiceMix的使用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:

persistence.xml中:

persistence.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>

骆驼context.xml中

camel-context.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(用常规)

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定义数据源。这导致了ClassNotFoundException在OpenJPA的包,因为它没有导入MySQL驱动程序。我想preFER在我的骆驼context.xml中定义这一点,将preFER不重新捆绑OpenJPA的罐子。

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.

推荐答案

您恐怕还需要安装白羊座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天全站免登陆