ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/InheritanceType
I got this error when try to build sessionFactory
my hibernate.cfg.xml file :
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">mateusz</property>
<property name="hibernate.connection.password">mateusz123</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/carpool</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<mapping class="org.mathew.data.User"></mapping>
</session-factory>
</hibernate-configuration>
my HibernateUtil class:
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
return new AnnotationConfiguration().configure().buildSessionFactory();
}
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public static void shutdown() {
// Close caches and connection pools
getSessionFactory().close();
}
}
StackTrace:
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.mathew.hibutil.HibernateUtil.buildSessionFactory(HibernateUtil.java:19)
at org.mathew.hibutil.HibernateUtil.<clinit>(HibernateUtil.java:8)
at org.mathew.mysql.MySqlQueries.<init>(MySqlQueries.java:16)
at org.mathew.test.AppMain.main(AppMain.java:8)
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/InheritanceType
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.hibernate.cfg.InheritanceState.extractInheritanceType(InheritanceState.java:51)
at org.hibernate.cfg.InheritanceState.<init>(InheritanceState.java:21)
at org.hibernate.cfg.AnnotationBinder.buildInheritanceStates(AnnotationBinder.java:2146)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:492)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:277)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1319)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:915)
at org.mathew.hibutil.HibernateUtil.buildSessionFactory(HibernateUtil.java:13)
... 3 more
My libraries:
cglib
commons-collections
commons-logging
dom4j
hibernate3
hibernate-annotations
hibernate-commons-annotations
hibernate-core
java-api-6.0
javassist
jta
log4j
mysql-connector-java
persistence-api
slf4j
slf4j-log4j
I can't upload image :)
I would be thankfull if anybody can help.
THANKS! :)
You seem to be managing your dependencies manually, you should really be using a dependency manager (maven, ivy with ant, etc.) to be sure you get the correct dependencies (all the libs in their expected version). Since you don't specify the versions of the libraries you're using, there are several possible problems:
Incompatible version of persistence-api with hibernate
Incompatible mix of hibernate jars: you apparently have a hibernate3 jar along with hibernate-core, that doesn't seem right. It looks like a old version of Hibernate mixed with more recent jars. So classes that only exist in the recent version might be accessing classes from the old one, if the jar comes first in the classpath.
Related
I am not very experienced with Hibernate yet and hava a problem when trying to create test data for my local database with Hibernate 4.3 and PostgreSQL.
I had another project where I did this exactly the same way and there it worked, so I did exactly the same setup but with another database, but now in my current project I get the following exception:
exception.DBException: Could not configure Hibernate!
at dao.BenutzerDAO.<init>(BenutzerDAO.java:48)
at export.ExportDBSchema.main(ExportDBSchema.java:16)
Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [org.postgresql.Driver]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:245)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.loadDriverIfPossible(DriverManagerConnectionProviderImpl.java:200)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildCreator(DriverManagerConnectionProviderImpl.java:156)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:95)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
at dao.BenutzerDAO.<init>(BenutzerDAO.java:45)
... 1 more
Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.postgresql.Driver
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:230)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:340)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:242)
... 15 more
I searched for possible solutions, but none of them worked for me:
-)Specify Classpath to jar in Manifest.mf -> Did not work
-)Place the postgresql-9.4.1208.jre6.jar in lib folder under WEB-INF -> Did not work
-)Specify hibernate.cfg.xml file in Configuration().configure(); -> Did not work
I use Glassfish 4.1 and the org.postgres.Driver.class is existing, so why is it not found?
My hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/Testdb</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<property name="hibernate.connection.password">password</property>
<mapping class="entity.Benutzer"/>
</session-factory>
</hibernate-configuration>
Method in BenutzerDAO.java where the exception occurs:
try {
if (sessionFactory == null) {
Configuration conf = new Configuration().configure();
StandardServiceRegistryBuilder builder
= new StandardServiceRegistryBuilder();
builder.applySettings(conf.getProperties());
sessionFactory = conf.buildSessionFactory(builder.build());
}
} catch (Throwable ex) {
throw new DBException("Could not configure Hibernate!", ex);
}
I would be very thankful for every answer.
try
{
Configuration cfg =new Configuration();
cfg.configure("hibernate.cfg.xml");
SessionFactory sf=cfg.buildSessionFactory();
Session sess=sf.openSession();
----------------------------------
your code
------------------------------
Transaction tx=sess.beginTransaction();
sess.save(e);
tx.commit();
sess.flush();
sess.close();
sf.close();
}
catch(Exception e)
{
System.out.println("e="+e.getMessage());
}
I am creating an app for school that generates business rules.
The front end consists of Apex and the backend is a java application that uses hibernate to access the database.
To communicate between Apex and Java I am using a rest service (using struts2).
This works fine when I deploy the application in my IDE (netbeans). But then it runs on my localhost. This way the Apex application can not connect to it. (The Apex application is hosted by my school)
So I tried deploying my application using various websites. The rest service part still works and I can connect the java app with my Apex application.
The problem is that the java application cant seem to connect to the database as soon as i deploy it online.
The glassfish console shows this when I try to get data from the database:
(Tosad is the name of the project/course)
[2016-01-08T15:23:07.004+0000] [glassfish 4.1] [INFO] [] []
[tid: _ThreadID=43 _ThreadName=Thread-8] [timeMillis: 1452266587004] [levelValue: 800] [[
[EL Severe]: ejb: 2016-01-08 15:23:07.004--ServerSession(1585495182)--
Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd):
org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [TOSAD].
Internal Exception: javax.naming.NamingException: Lookup failed for 'TOSAD' in SerialContext[
myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory,
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,
java.naming.factory.url.pkgs=com.sun.enterprise.naming}
[Root exception is javax.naming.NameNotFoundException: TOSAD not found]]]
Hibernate.cfg.xml (I replaced some info for safety purposes)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:#ondora02.hu.nl:PORT:COURSE</property>
<property name="hibernate.connection.username">USERNAME</property>
<property name="hibernate.connection.password">PASSWORD</property>
</session-factory>
</hibernate-configuration>
HibernateUtil.java
package Service;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class HibernateUtil {
private static String orclcfg = "nl.hu.ict.jpa.oracle";
private static String mysqlcfg = "nl.hu.ict.jpa.mysql";
private static boolean mysql = false;
private static String dbcfg = orclcfg;
private static final EntityManagerFactory entityManagerFactory;
//entityManagerFactory = Persistence.createEntityManagerFactory("nl.hu.ict.jpa.oracle" );
static {
try {
if (!mysql) {
dbcfg = orclcfg;
}
entityManagerFactory = Persistence.createEntityManagerFactory(dbcfg);
} catch (Throwable th) {
System.err.println("Initial EntityManagerFactory creation failed" + th);
throw new ExceptionInInitializerError(th);
}
}
public static EntityManagerFactory getEntityManagerFactory() {
return entityManagerFactory;
}
}
The error message is somewhat clear. The JNDI resource named TOSAD cannot be located on your remote deployed server. Make sure it is configured on the remote server like you likely have done on your local machine.
I know there are other questions about this topic in StackOverflow, I read them but I can't get rid off this error.
I'm deploying my web app in JBoss-as-7.1.1 Final. It's a Maven proyect.
When I go to sapo-ear, rigth click, run as, maven install, it says "build succesfull". Then I try to full publish it in JBoss and then it says:
23:59:26,009 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC00001: Failed to start service jboss.persistenceunit."SAPo-ear.ear/SAPo-ejb.jar#sapo": org.jboss.msc.service.StartException in service jboss.persistenceunit."SAPo-ear.ear/SAPo-ejb.jar#sapo": Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_80-ea]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_80-ea]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_80-ea]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: sapo] class or package not found
at org.hibernate.ejb.Ejb3Configuration.addNamedAnnotatedClasses(Ejb3Configuration.java:1400)
at org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:1183)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1047)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:692)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:72)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
... 3 more
Caused by: java.lang.ClassNotFoundException: uy.edu.fing.tsi2.sapo.entities.Administrador from [Module "org.hibernate:main" from local module loader #beaed3 (roots: C:\Program Files\jboss-as-7.1.1.Final\modules)]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
at java.lang.Class.forName0(Native Method) [rt.jar:1.7.0_80-ea]
at java.lang.Class.forName(Class.java:278) [rt.jar:1.7.0_80-ea]
at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:170)
at org.hibernate.ejb.Ejb3Configuration.classForName(Ejb3Configuration.java:1317)
at org.hibernate.ejb.Ejb3Configuration.addNamedAnnotatedClasses(Ejb3Configuration.java:1389)
... 11 more
As far as I know, this could be caused by an inconsistence between persistence.xml and Adminstrador class.
Here is my persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
<persistence-unit name="sapo">
<jta-data-source>java:jboss/datasources/sapo</jta-data-source>
<class>sapo.entities.Administrador</class>
<class>sapo.entities.Almacen</class>
<class>sapo.entities.AtributoValor</class>
<class>sapo.entities.Comentario</class>
<class>sapo.entities.Estandar</class>
<class>sapo.entities.Mensaje</class>
<class>sapo.entities.Producto</class>
<class>sapo.entities.RolEnAlmacen</class>
<class>sapo.entities.CatCompleja</class>
<class>sapo.entities.ProductoGenerico</class>
<class>sapo.entities.TransaccionInterna</class>
<class>sapo.entities.TransaccionExterna</class>
<properties>
<!-- Properties for Hibernate -->
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
</properties>
</persistence-unit>
And this is my Administrador class
#Entity
public class Administrador extends Usuario {
public Administrador(){
}
public Administrador(String nick, String password, String nombre,
String mail, String direccion, Date fechaNacimiento,
String linkImagen) {
super(nick, password, nombre, mail, direccion, fechaNacimiento, linkImagen);
// TODO Auto-generated constructor stub
}
}
Usuario is an abstrac class
#Entity
#Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class Usuario {
#Id
#GeneratedValue(strategy=GenerationType.TABLE)
#Basic(optional = false)
private Long id;
//attribs, Getters setters and other methods
}
The most strange is this line from jboss stack trace
java.lang.ClassNotFoundException: uy.edu.fing.tsi2.sapo.entities.Administrador
This directory was all changed to just sapo.entities.Administrador, the long path was from an old version. I deleted this old project and cloned it again from git, I also deleted all files from C:\Program Files\jboss-as-7.1.1.Final\standalone\deployments but stack trace keep throwing this old path.
My team mates are using the same configuration, cloned from the same git repository without any problem while I'm stacked with this.
Finally I solved it, it was a problem in maven project configuration in one of the pom.xml, we had some problems with group ids from artefact and parents.
I don't have the exact answer because my team mate was who solved it, I'll ask her and update this answer with more detail later.
If you have entries in your xml file as well as annotation for the corresponding class then sometime it cause problems. Try to remove one of both either annotation or xml entry for the corresponding class and then run again. Hope this helps.
I just updated Hibernate in my application to 4.3.4 (from 3.X), which caused some problems. The first was the new method of creating a sessionFactory, which I resolved.
The next problem, which I'm finding nothing about, is that I am now getting a ClassNotFoundException on org.hibernate.connection.ConnectionProvider
It should be noted that I'm using BoneCP (0.7.1) for my connection pool, which was working before the upgrade.
Any help would be appreciated. I'm pretty new to hibernate (I'm working on implementing it as a POC), and I may have left out some important details from my description here as such.
I don't need it to be the newest version, so I can revert back, but it would be nice to have the latest and greatest :)
Thanks!
Hibernate.cfg.xml snippet (with sensitive info replaced):
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">foo</property>
<property name="hibernate.connection.username">bob</property>
<property name="hibernate.default_schema">bar</property>
<property name="hibernate.dialect">package.path.MySQLCustomDialect</property>
<!-- Bonecp connection pool -->
<property name="hibernate.connection.provider_class">com.jolbox.bonecp.provider.BoneCPConnectionProvider</property>
<property name="bonecp.maxConnectionAgeInMinutes">5</property>
<property name="bonecp.idleConnectionTestPeriodInMinutes">0</property>
and so on ...
Stack Trace:
Exception in thread "Thread-110" java.lang.NoClassDefFoundError: org/hibernate/connection/ConnectionProvider
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2895)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1173)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1681)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:222)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:249)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:240)
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:125)
at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:194)
at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:120)
at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:55)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:83)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:223)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:197)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
at foo.utils.HibernateUtils.<clinit>(HibernateUtils.java:16)
at foo.objects.building.BuildingHelper.getBuildingByID(BuildingHelper.java:225)
at foo.objects.inventory.LocationInformation.<init>(LocationInformation.java:36)
at foo.objects.computermanagementframework.peripheral.PeripheralHelper.readLocation(PeripheralHelper.java:154)
at foo.objects.computermanagementframework.peripheral.PeripheralHelper.refresh(PeripheralHelper.java:556)
at foo.server.initialization.InitializeServerThread.run(InitializeServerThread.java:298)
at java.lang.Thread.run(Thread.java:695)
Caused by: java.lang.ClassNotFoundException: org.hibernate.connection.ConnectionProvider
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
... 36 more
Hibernate keeps changing the package containing the ConnectionProvider base class. It changed from version 3 to 4 and has changed again with verson 4.3.
As #teresa-carrigan mentions in a comment to this answer, you'll have to compile the latest BoneCPConnectionProvider.java (currently supporting Hibernate 4.3.1) and use that.
Or use Hibernate version 4.2.12.Final and see if that works with BoneCP 0.8 (as explained in the aforementioned answer).
I'm new at Spring MVC. I'm using STS and I've created Spring MVC Template Project (which uses Maven by default). I'm trying to use Hibernate and i know that in default Java Projects i have to put hibernate.xml.cfg in /src folder. I've read that in my case (with Spring MVC Template with maven) i have to put hibernate.cfg.xml in src/main/resources and in /WEB-INF/classes. But it didn't help too. I still have ClassNotFoundException:
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/mvc] threw exception [Handler processing failed; nested exception is java.lang.ExceptionInInitializerError] with root cause
java.lang.ClassNotFoundException: org.dom4j.DocumentException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
at com.andrew.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:18)
at com.andrew.hibernate.DAO.getStudent(DAO.java:48)
at com.andrew.mvc.HomeController.home(HomeController.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Here is my hibernate.cfg.xml:
<?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>
<!-- Database connection settings -->
<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="connection.url">jdbc:sqlserver://localhost:1433</property>
<property name="connection.username">hibernate</property>
<property name="connection.password">123456</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Mapping files -->
<mapping class="com.andrew.ModelPackage.Student"/>
<mapping class="com.andrew.ModelPackage.Subject"/>
</session-factory>
</hibernate-configuration>
My HibernateUtil class:
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
//AnnotationConfiguration
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Maybe i should write something about hibernate.cfg.xml in web.xml or in servlet-context.xml? I'm fighting with this problem about 7 hours and i tried even put hibernate.cfg.xml in every folder in the project but it didn't helped.
IMO is not a problem with the location of your hibernate.cfx.xml, but looks like a missing library. You should add the dom4j.jar in your classpath.