I am working on a project using Hibernate 4.3.11.Final and karaf 4.0.2. When loading the hibernate config I get the following exception, However the class that fails loading is in the bundle. I Hope somebody can help me with this problem. I have been trying to fix it for several days and I am running out of ideas.
Thanks
org.osgi.framework.ServiceException: Service factory exception: Unable to load class [ com.asm.infraMngr.database.entity.GroupRoleRoleItem] declared in Hibernate configuration <mapping/> entry at org.apache.felix.framework.ServiceRegistrationImpl.getFactoryUnchecked(ServiceRegistrationImpl.java:352)[org.apache.felix.framework-5.2.0.jar:] at org.apache.felix.framework.ServiceRegistrationImpl.getService(ServiceRegistrationImpl.java:247)[org.apache.felix.framework-5.2.0.jar:] at org.apache.felix.framework.ServiceRegistry.getService(ServiceRegistry.java:343)[org.apache.felix.framework-5.2.0.jar:] at org.apache.felix.framework.Felix.getService(Felix.java:3692)[org.apache.felix.framework-5.2.0.jar:] at org.apache.felix.framework.BundleContextImpl.getService(BundleContextImpl.java:470)[org.apache.felix.framework-5.2.0.jar:] at com.asm.infraMngr.database.sessionFactory.HibernateUtil.getSessionFactory(HibernateUtil.java:39)[119:com.asm.infraMngr.database:0.0.1] at com.asm.infraMngr.database.sessionFactory.HibernateUtil.getSession(HibernateUtil.java:29)[119:com.asm.infraMngr.database:0.0.1] at com.asm.infraMngr.database.security.daoImpl.UsersDaoImpl.addUser(UsersDaoImpl.java:64)[119:com.asm.infraMngr.database:0.0.1] at com.asm.infraMngr.AppTesting.activator.Activator.start(Activator.java:50)[122:com.asm.infraMngr.AppTesting:0.0.1] at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:697)[org.apache.felix.framework-5.2.0.jar:] at org.apache.felix.framework.Felix.activateBundle(Felix.java:2220)[org.apache.felix.framework-5.2.0.jar:] at org.apache.felix.framework.Felix.startBundle(Felix.java:2138)[org.apache.felix.framework-5.2.0.jar:] at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:977)[org.apache.felix.framework-5.2.0.jar:] at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:964)[org.apache.felix.framework-5.2.0.jar:] at org.apache.karaf.bundle.command.Install.execute(Install.java:96)[23:org.apache.karaf.bundle.core:4.0.2] at org.apache.karaf.shell.impl.action.command.ActionCommand.execute(ActionCommand.java:83)[43:org.apache.karaf.shell.core:4.0.2] at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:67)[43:org.apache.karaf.shell.core:4.0.2] at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:87)[43:org.apache.karaf.shell.core:4.0.2] at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480)[43:org.apache.karaf.shell.core:4.0.2] at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)[43:org.apache.karaf.shell.core:4.0.2] at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)[43:org.apache.karaf.shell.core:4.0.2] at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182)[43:org.apache.karaf.shell.core:4.0.2] at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119)[43:org.apache.karaf.shell.core:4.0.2] at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)[43:org.apache.karaf.shell.core:4.0.2] at org.apache.karaf.shell.impl.console.ConsoleSessionImpl.run(ConsoleSessionImpl.java:268)[43:org.apache.karaf.shell.core:4.0.2] at java.lang.Thread.run(Thread.java:745)[:1.8.0_40] Caused by: org.hibernate.MappingException: Unable to load class [ com.asm.infraMngr.database.entity.GroupRoleRoleItem] declared in Hibernate configuration <mapping/> entry at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2281)[97:org.hibernate.core:4.3.11.Final] at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2229)[97:org.hibernate.core:4.3.11.Final] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2209)[97:org.hibernate.core:4.3.11.Final] at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2162)[97:org.hibernate.core:4.3.11.Final] at org.hibernate.cfg.Configuration.configure(Configuration.java:2077)[97:org.hibernate.core:4.3.11.Final] at org.hibernate.osgi.OsgiSessionFactoryService.getService(OsgiSessionFactoryService.java:102)[100:org.hibernate.osgi:4.3.11.Final] at org.apache.felix.framework.ServiceRegistrationImpl.getFactoryUnchecked(ServiceRegistrationImpl.java:347)[org.apache.felix.framework-5.2.0.jar:] ... 25 more Caused by: java.lang.ClassNotFoundException: com.asm.infraMngr.database.entity.GroupRoleRoleItem not found by org.hibernate.core [97] at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1558)[org.apache.felix.framework-5.2.0.jar:] at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)[org.apache.felix.framework-5.2.0.jar:] at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1998) at java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_40] at java.lang.Class.forName0(Native Method)[:1.8.0_40] at java.lang.Class.forName(Class.java:264)[:1.8.0_40] at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:193)[97:org.hibernate.core:4.3.11.Final] at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2278)[97:org.hibernate.core:4.3.11.Final]
################################################################################### Below my hibernate config
<?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">org.apache.derby.jdbc.EmbeddedDriver</property> <property name="hibernate.connection.url">jdbc:derby:ASM_DB;create=true</property> <property name="hibernate.connection.username">test</property> <property name="hibernate.connection.password">test</property> <property name="hibernate.dialect">org.hibernate.dialect.DerbyTenSevenDialect</property> <property name="hibernate.hbm2ddl.auto">create-drop</property>
<mapping class="com.asm.infraMngr.database.entity.Users" /> <mapping class="com.asm.infraMngr.database.entity.Group" /> <mapping class="com.asm.infraMngr.database.entity.GroupRole" /> <mapping class="com.asm.infraMngr.database.entity.GroupRoleRoleItem" /> <mapping class="com.asm.infraMngr.database.entity.ItService" /> <mapping class="com.asm.infraMngr.database.entity.HttpInfo" /> <mapping class="com.asm.infraMngr.database.entity.JmxInfo" /> <mapping class="com.asm.infraMngr.database.entity.ServerInfo" /> <mapping class="com.asm.infraMngr.database.entity.SshInfo" /> <mapping class="com.asm.infraMngr.database.entity.UserAttempts" /> <mapping class="com.asm.infraMngr.database.entity.ServiceAudit" /> </session-factory> </hibernate-configuration>
################################################################################### I am loading the hibernate session with the following class
import org.hibernate.Session; import org.hibernate.SessionFactory; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference;
public class HibernateUtil {
private SessionFactory sf;
public Session getSession() { return getSessionFactory().openSession(); }
private SessionFactory getSessionFactory() { if ( sf == null ) { Bundle thisBundle = FrameworkUtil.getBundle( HibernateUtil.class ); // Could get this by wiring up OsgiTestBundleActivator as well. BundleContext context = thisBundle.getBundleContext();
ServiceReference sr = context.getServiceReference( SessionFactory.class.getName() ); sf = (SessionFactory) context.getService( sr ); } return sf; } }
#################################################################################### The POM dependencies are the following
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <hibernate.core.version>4.3.11.Final</hibernate.core.version> <bundle.symbolicName>com.asm.infraMngr.database</bundle.symbolicName> <bundle.namespace>com.asm.infraMngr.database</bundle.namespace>
</properties>
<build>
<plugins>
<plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <version>2.4.0</version> <extensions>true</extensions> <!-- the following instructions build a simple set of public/private classes into an OSGi bundle --> <configuration> <manifestLocation>META-INF</manifestLocation> <instructions> <Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName> <Bundle-Version>${pom.version}</Bundle-Version> <Bundle-Activator>com.asm.infraMngr.database.activator.ActivatorDBModule</Bundle-Activator> <Spring-Context>*;publish-context:=false;create-asynchronously:=true</Spring-Context> <Bundle-ClassPath>.,./config/</Bundle-ClassPath> <DynamicImport-Package>*</DynamicImport-Package> <Bundle-ManifestVersion>2</Bundle-ManifestVersion> <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy> <Export-Package> com.asm.infraMngr.database.services.dao, com.asm.infraMngr.database.security.dao, com.asm.infraMngr.database.entity </Export-Package> <Import-Package> org.hibernate;version=${hibernate.core.version}, org.hibernate.cfg;version=${hibernate.core.version}, org.hibernate.service;version=${hibernate.core.version}, org.hibernate.proxy;version=${hibernate.core.version}, org.hibernate.mapping;version=${hibernate.core.version}, org.hibernate.annotations;version=${hibernate.core.version}, org.hibernate.envers.*;version=${hibernate.core.version}, org.hibernate.boot.registry;version=${hibernate.core.version}, org.osgi.framework;version=1.0, org.jvnet.jaxb2_commons.lang;version=0, org.jvnet.jaxb2_commons.locator;version=0, org.apache.log4j;version=1.2.15, org.apache.derby.jdbc;version=10.12.1.1, javax.xml.datatype;version=0.0.0 </Import-Package> </instructions> </configuration> </plugin>
</plugins>
</build>
<dependencies> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>${hibernate.core.version}</version> <scope>provided</scope> <exclusions> <exclusion> <groupId>xml-apis</groupId> <artifactId>xml-apis</artifactId> </exclusion> <exclusion> <groupId>xerces</groupId> <artifactId>xercesImpl</artifactId> </exclusion> </exclusions> </dependency>
<dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-envers</artifactId> <version>${hibernate.core.version}</version> <scope>provided</scope> </dependency>
<dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> <version>0.9.1.2</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.apache.servicemix.bundles</groupId> <artifactId>org.apache.servicemix.bundles.derby</artifactId> <version>10.12.1.1_1</version> </dependency>
<dependency> <groupId>org.jvnet.hyperjaxb3</groupId> <artifactId>hyperjaxb3-ejb-runtime</artifactId> <version>0.5.6</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.jvnet.jaxb2_commons</groupId> <artifactId>runtime</artifactId> <version>0.4.1.5</version> <scope>provided</scope> </dependency>
<dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.core</artifactId> <version>5.0.0</version> <!--scope>provided</scope--> </dependency>
</dependencies>
|