java.lang.NoClassDefFoundError: org/hibernate/cfg/Mappings

Dear Experts,
We have hibernate applications with old lib, the libs were built by java 1.1 to java 1.5. for example, hibernate3.jar is build by java 1.4 (major version 48). I am trying to upgrade it to java 1.8. I load the lib:

geolatte-geom-1.3.0.jar	
jandex-2.0.3.Final.jar	javassist-3.22.0-GA.jar
byte-buddy-1.8.12.jar	org.osgi.core-4.3.1.jar
postgresql-42.2.2.jar	commons-collections4-4.2.jar
commons-lang3-3.7.jar	javax.interceptor-api-1.2.jar
log4j-core-2.23.1.jar	javax.persistence-api-2.2.jar
log4j-api-2.23.1.jar	       jboss-logging-3.3.2.Final.jar
classmate-1.3.4.jar		org.osgi.compendium-4.3.1.jar
jts-core-1.14.0.jar		hibernate-c3p0-5.3.1.Final.jar
slf4j-api-1.6.1.jar		hibernate-core-5.3.1.Final.jar
ojdbc8-19.3.0.0.jar		hibernate-osgi-5.3.1.Final.jar
java-mail-1.4.4.jar		mchange-commons-java-0.2.11.jar
proxool-0.8.3.jar		hibernate-envers-5.3.1.Final.jar
junique-1.0.4.jar		hibernate-proxool-5.3.1.Final.jar
c3p0-0.9.5.2.jar		hibernate-spatial-5.3.1.Final.jar
junit5-4.6.7.jar		hibernate-jpamodelgen-5.3.1.Final.jar
antlr-2.7.7.jar	         hibernate-annotations-3.5.6-Final.jar
dom4j-1.6.1.jar        hibernate-commons-annotations-5.0.3.Final.jar
log4j-3.1.2.jar	        jboss-transaction-api_1.2_spec-1.1.1.Final.jar

Based on existed hbm.xml files, did some modification, and not changed java mapping class,
The hibernate.cfg.xml list all the hbm.xml files, not mentioned the class. the header of the hbm.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 5.3//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-5.3.dtd" >
....

I put the hibernate.cfg.xml under \src,
in a class:

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
...   ....
AnnotationConfiguration config = new AnnotationConfiguration().configure(); 	

the line above caused error:

java.lang.NoClassDefFoundError: org/hibernate/cfg/Mappings
Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.Mappings
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	... 26 more

There is one seen problem. if put http://hibernate.sourceforge.net/hibernate-mapping-5.3.dtd in Chrome, I get 404 error. if change to 3.0.dtd, Chrome has no 404 error, but my application get the same error.
I am working on eclipse, oracle 19c. Could you please teach me how to fix it?
Thanks,
Eric

You are using very old versions of Hibernate, so it’s really hard to provide accurate information. It looks like a class loading problem, something in your application is requesting org.hibernate.cfg.Mappings and it’s not being found. This might be due to incompatible library versions.

Are you adding jar files manually to your application’s classpath? I would suggest using a build tool (e.g. Gradle or Maven) to handle dependency management, using the same version for all hibernate-related artifacts, and maybe consider upgrading to Hibernate’s latest version 6.5 series - Hibernate ORM.

1 Like

Hi mbladel,
I added jar through properties/java build path. not use Maven.
We decided to take your suggestion, go with version Hibernate 6.5, JDK11.0.22, Oracle 19.C. At the end of your post, the link points a good source, but seems misses seems details. We upgrade from too old application, the gap is so large. I mostly concern the miss-match lib jars (such as Maven vs no Manen) cause problem. Do you know if there is a good book matches the concepts, could you please recommend? it will be very helpful.
Our current application does not use Maven, I wonder if I can avoid it.

Appreciate your help,
Thanks,
Eric

Maven is a good feature, I like it.