2013-07-11 60 views
0

我已經花了一週試圖JPA /集成的ServiceMix 4.5.1 /駱駝JPA 2.10.4 /藍圖在一起。我目前正在使用OpenJPA,但並未與此綁定。 servicemix使用的aries jpa版本是0.3.0。的ServiceMix /藍圖/ JPA集成

堆棧跟蹤我不能讓過去的是:

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

我已經嘗試了好變化。這是我目前的配置:

的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

<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 
@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) { 
     // ... 
    } 
} 

我已經嘗試了多個不同的DataSource實現,包括BasicDataSource,org.springframework.jdbc.datasou rce.SimpleDriverDataSource和com.mysql.jdbc.jdbc2.optional.MysqlDataSource。全部導致IllegalArgumentException。

我也嘗試使用JNDI放棄,而是直接在persistence.xml定義數據源。這會導致OpenJPA包中的ClassNotFoundException,因爲它不會導入mysql驅動程序。我更喜歡在我的camel-context.xml中定義這個,並且不希望重新綁定OpenJPA jar。

回答

1

您可能還需要安裝aries JNDI功能。這有助於通過JNDI查找調用OSGi服務。這應該是缺失的一塊。