JBoss Fuse +JPA/Hibernate -
i have osgi bundle in jboss fuse 6.2 imports jar entities , dao classes.
jar contains:
spring.xml
<?xml version="1.0" encoding="utf-8"?> <!-- configures camel context--> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:security="http://www.springframework.org/schema/security" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:jpa="http://www.springframework.org/schema/data/jpa" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> <context:component-scan base-package="com.company"/> <tx:annotation-driven transaction-manager="transactionmanager" /> <bean id="transactionmanager" class="org.springframework.orm.jpa.jpatransactionmanager"> <property name="entitymanagerfactory" ref="entitymanagerfactory" /> <property name="datasource" ref="datasource" /> <property name="jpadialect" ref="jpadialect" /> </bean> <bean id="entitymanagerfactory" class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean"> <property name="persistencexmllocation" value="classpath:meta-inf/persistence.xml" /> <property name="persistenceunitname" value="jpadata" /> <property name="datasource" ref="datasource" /> <property name="jpavendoradapter" ref="jpavendoradapter" /> <property name="jpadialect" ref="jpadialect" /> </bean> <bean id="jpavendoradapter" class="org.springframework.orm.jpa.vendor.hibernatejpavendoradapter"> <property name="database" value="postgresql" /> <property name="databaseplatform" value="org.hibernate.dialect.postgresqldialect" /> </bean> <bean id="jpadialect" class="org.springframework.orm.jpa.vendor.hibernatejpadialect" /> <bean id="datasource" class="org.springframework.jdbc.datasource.simpledriverdatasource"> <property name="driverclass" value="org.postgresql.driver" /> <property name="url" value="jdbc:postgresql://localhost:5432/mydb" /> <property name="username" value="postgres" /> <property name="password" value="123456" /> </bean> </beans>
persistence.xml
<?xml version="1.0" encoding="utf-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="jpadata" transaction-type="resource_local" > <provider>org.hibernate.ejb.hibernatepersistence</provider> <class>com.company.model.entity.entity</class> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.postgresqldialect"/> <property name="hibernate.archive.autodetection" value="class"/> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="hbm2ddl.auto" value="update"/> </properties> </persistence-unit> </persistence>
dao class
@repository @transactional public class jpaentitydao implements entitydao { @persistencecontext(unitname="jpadata") private entitymanager em; //methods use entitymanager }
entity class
@entity @table(name="entity", schema="public") public class entity { //fields setters , getters }
i want use jpaentitydao in bundle. imported spring.xml jar bundle's spring xml
when install bundle in karaf error appears:
16:27:30,684 | error | extenderthread-8 | contextloaderlistener | 174 - org.springframework.osgi.extender - 1.2.1 | application context refresh failed (osgibundlexmlapplicationcontext(bundle=mybundle, config=osgibundle:/meta-inf/spring/*.xml)) org.springframework.beans.factory.beancreationexception: error creating bean name 'entitymanagerfactory' defined in url [bundle://749.0:1/meta-inf/spring/spring.xml]: invocation of init method failed; nested exception javax.persistence.persistenceexception: [persistenceunit: jpadata] class or package not found @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1514)[167:org.apache.servicemix.bundles.spring-beans:3.2.12.release_1] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:521)[167:org.apache.servicemix.bundles.spring-beans:3.2.12.release_1] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.createbean(abstractautowirecapablebeanfactory.java:458)[167:org.apache.servicemix.bundles.spring-beans:3.2.12.release_1] @ org.springframework.beans.factory.support.abstractbeanfactory$1.getobject(abstractbeanfactory.java:293)[167:org.apache.servicemix.bundles.spring-beans:3.2.12.release_1] @ org.springframework.beans.factory.support.defaultsingletonbeanregistry.getsingleton(defaultsingletonbeanregistry.java:223)[167:org.apache.servicemix.bundles.spring-beans:3.2.12.release_1] @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:290)[167:org.apache.servicemix.bundles.spring-beans:3.2.12.release_1] @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:191)[167:org.apache.servicemix.bundles.spring-beans:3.2.12.release_1] @ org.springframework.context.support.abstractapplicationcontext.getbean(abstractapplicationcontext.java:1119)[169:org.apache.servicemix.bundles.spring-context:3.2.12.release_1] @ org.springframework.context.support.abstractapplicationcontext.finishbeanfactoryinitialization(abstractapplicationcontext.java:924)[169:org.apache.servicemix.bundles.spring-context:3.2.12.release_1] @ org.springframework.osgi.context.support.abstractdelegatedexecutionapplicationcontext.access$1600(abstractdelegatedexecutionapplicationcontext.java:69)[173:org.springframework.osgi.core:1.2.1] @ org.springframework.osgi.context.support.abstractdelegatedexecutionapplicationcontext$4.run(abstractdelegatedexecutionapplicationcontext.java:355)[173:org.springframework.osgi.core:1.2.1] @ org.springframework.osgi.util.internal.privilegedutils.executewithcustomtccl(privilegedutils.java:85)[173:org.springframework.osgi.core:1.2.1] @ org.springframework.osgi.context.support.abstractdelegatedexecutionapplicationcontext.completerefresh(abstractdelegatedexecutionapplicationcontext.java:320)[173:org.springframework.osgi.core:1.2.1] @ org.springframework.osgi.extender.internal.dependencies.startup.dependencywaiterapplicationcontextexecutor$completerefreshtask.run(dependencywaiterapplicationcontextexecutor.java:132)[174:org.springframework.osgi.extender:1.2.1] @ java.lang.thread.run(thread.java:745)[:1.8.0_65] caused by: javax.persistence.persistenceexception: [persistenceunit: jpadata] class or package not found @ org.hibernate.ejb.ejb3configuration.addnamedannotatedclasses(ejb3configuration.java:1431)[668:org.hibernate.entitymanager:4.2.19.final-redhat-1] @ org.hibernate.ejb.ejb3configuration.addclassestosessionfactory(ejb3configuration.java:1214)[668:org.hibernate.entitymanager:4.2.19.final-redhat-1] @ org.hibernate.ejb.ejb3configuration.configure(ejb3configuration.java:1058)[668:org.hibernate.entitymanager:4.2.19.final-redhat-1] @ org.hibernate.ejb.ejb3configuration.configure(ejb3configuration.java:703)[668:org.hibernate.entitymanager:4.2.19.final-redhat-1] @ org.hibernate.ejb.hibernatepersistence.createcontainerentitymanagerfactory(hibernatepersistence.java:75)[668:org.hibernate.entitymanager:4.2.19.final-redhat-1] @ org.springframework.orm.jpa.localcontainerentitymanagerfactorybean.createnativeentitymanagerfactory(localcontainerentitymanagerfactorybean.java:290)[716:org.apache.servicemix.bundles.spring-orm:3.2.12.release_1] @ org.springframework.orm.jpa.abstractentitymanagerfactorybean.afterpropertiesset(abstractentitymanagerfactorybean.java:310)[716:org.apache.servicemix.bundles.spring-orm:3.2.12.release_1] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.invokeinitmethods(abstractautowirecapablebeanfactory.java:1573)[167:org.apache.servicemix.bundles.spring-beans:3.2.12.release_1] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.initializebean(abstractautowirecapablebeanfactory.java:1511)[167:org.apache.servicemix.bundles.spring-beans:3.2.12.release_1] ... 14 more caused by: java.lang.classnotfoundexception: com.company.model.entity not found org.hibernate.entitymanager [668] @ org.apache.felix.framework.bundlewiringimpl.findclassorresourcebydelegation(bundlewiringimpl.java:1556)[org.apache.felix.framework-4.4.1.jar:] @ org.apache.felix.framework.bundlewiringimpl.access$400(bundlewiringimpl.java:77)[org.apache.felix.framework-4.4.1.jar:] @ org.apache.felix.framework.bundlewiringimpl$bundleclassloader.loadclass(bundlewiringimpl.java:1993) @ java.lang.classloader.loadclass(classloader.java:357)[:1.8.0_65] @ java.lang.class.forname0(native method)[:1.8.0_65] @ java.lang.class.forname(class.java:348)[:1.8.0_65] @ org.hibernate.internal.util.reflecthelper.classforname(reflecthelper.java:170)[670:org.hibernate.core:4.2.19.final-redhat-1] @ org.hibernate.ejb.ejb3configuration.classforname(ejb3configuration.java:1348)[668:org.hibernate.entitymanager:4.2.19.final-redhat-1] @ org.hibernate.ejb.ejb3configuration.addnamedannotatedclasses(ejb3configuration.java:1420)[668:org.hibernate.entitymanager:4.2.19.final-redhat-1] ... 22 more
it seems karaf finds class definition in persistence.xml can't load entity class.
suggestions welcome.
it seems spring bad choice osgi, , confirmed there using both blueprint , spring (not spring-dm) osgi.
so necessary use apache aries. can find working example jpa+fuse there https://github.com/pires/fabric8-persistence-hibernate
https://github.com/fusebyexample .
Comments
Post a Comment