Herewith I added my source code of web.xml
I usualy get those java.lang.NoClassDefFoundError when the class appears MORE THAN ONCE in the classloader. Check the jars because, if the same class is present in more than one (maybe included both in the webservice client jar AND elsewhere) the java classloader will not know which one to load, even if it's exactly the same class.
According codejava.net the HibernateUtil for hibernate-core-4.x
looks like this:
...
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
public class HibernateUtil {
private static SessionFactory sessionFactory;
public static SessionFactory getSessionFactory() {
if (sessionFactory == null) {
// loads configuration and mappings
Configuration configuration = new Configuration().configure();
ServiceRegistry serviceRegistry
= new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
// builds a session factory from the service registry
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
return sessionFactory;
}
}
....
It is slightly optically different than example above, but the effect is the same. It is needed, to ensure, that old dictionary hibernate-3.x
is really not present.
This Kind of an error can be happened when initialization of SessionFactory
fails. You have mentioned that you are using hibernate-core-4.3.7
. The way you are initializing the SessionFactory
is not the correct for this version. Use Hibernate version 3.x or change the way you are initializing the SessionFactory
. Below is the correct way to build the session factory in Hibernate 4.x +
.
Configuration configuration = new Configuration().configure();
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().
applySettings(configuration.getProperties());
SessionFactory factory = configuration.buildSessionFactory(builder.build());
Some classes are missing when com.dialog.mife.ussd.util.HibernateUtil class is initialized(e.g, static field or static initializing block).
Make sure whether all libraries are located in lib directory when you run the servlet.
In the HibernateUtils, there is reference for the "/hibernate.cfg.xml" file. In which we have to add the hbm.xml mapping. also confirm that mapping file present in the resource file.