-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Hibernate and Karaf java.lang.ClassNotFoundException:
PostPosted: Wed Nov 25, 2015 1:36 pm 
Newbie

Joined: Wed Nov 25, 2015 1:10 pm
Posts: 3
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>


Top
 Profile  
 
 Post subject: Re: Hibernate and Karaf java.lang.ClassNotFoundException:
PostPosted: Wed Nov 25, 2015 2:20 pm 
Regular
Regular

Joined: Mon Oct 19, 2015 7:49 am
Posts: 61
Location: ChengDu China
I do not know karaf, so I have to try to guess the reason. Please add org.hibernate.internal.util into the xml element import-package


Top
 Profile  
 
 Post subject: Re: Hibernate and Karaf java.lang.ClassNotFoundException:
PostPosted: Wed Nov 25, 2015 2:57 pm 
Newbie

Joined: Wed Nov 25, 2015 1:10 pm
Posts: 3
Thanks for the reply. I added the missing import, extraneously I have now the following exception. Although my hibernate.cfg.xml is on the resources directory under my maven project. So when I build the project is is put on the root of the bundle.

org.osgi.framework.ServiceException: Service factory exception: /hibernate.cfg.xml not found
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)[125:com.asm.infraMngr.database:0.0.1]
at com.asm.infraMngr.database.sessionFactory.HibernateUtil.getSession(HibernateUtil.java:29)[125:com.asm.infraMngr.database:0.0.1]
at com.asm.infraMngr.database.security.daoImpl.UsersDaoImpl.addUser(UsersDaoImpl.java:64)[125:com.asm.infraMngr.database:0.0.1]
at com.asm.infraMngr.AppTesting.activator.Activator.start(Activator.java:50)[126: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.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.internal.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:173)[97:org.hibernate.core:4.3.11.Final]
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:2095)[97:org.hibernate.core:4.3.11.Final]
at org.hibernate.cfg.Configuration.configure(Configuration.java:2076)[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


Top
 Profile  
 
 Post subject: Re: Hibernate and Karaf java.lang.ClassNotFoundException:
PostPosted: Thu Nov 26, 2015 1:03 am 
Regular
Regular

Joined: Mon Oct 19, 2015 7:49 am
Posts: 61
Location: ChengDu China
Oh no, maybe some other code and configuration has been changed by you. The first exception can only be raise when the hibernate.cfg.xml is found, now the new exception raised earlier so that I can't know whether this modification is useful, please carefully check whether everything is not changed except the change of my suggestion.


Top
 Profile  
 
 Post subject: Re: Hibernate and Karaf java.lang.ClassNotFoundException:
PostPosted: Mon Nov 30, 2015 10:36 am 
Newbie

Joined: Wed Nov 25, 2015 1:10 pm
Posts: 3
I was able to solve the problem, form some reason Karaf keeps references on an old hibernate bundle even after uninstalling the bundle, so the hibernate config file was not found by karaf. To solve the problem I deleted the "data" directory in karaf to restart fresh. Then I installed all the dependencies and finally my bundle. Then the hibernate config file was found on the bundle started up correctly.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.