问题
Trying hibernate & doing as manuals say. But it doesn't work.
package util;
//imports
public class HibernateUtil {
private static SessionFactory sessionFactory = null;
static {
try {
System.out.println("HU 01");
Configuration configuration = new Configuration();
System.out.println("HU 02");
configuration.configure();
System.out.println("HU 03");
//creates the session factory from hibernate.cfg.xml
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
System.out.println("HU 04");
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
System.out.println("HU 05");
} catch (Exception e) {
System.out.println("HU 06");
e.printStackTrace();
}
}
public static SessionFactory getSessionFactory() {
System.out.println("HU 00");
return sessionFactory;
}
}
I've got next logs (placed System.out... everywhere):
Main class starts.
Factory initialised.
Factory.Entity initialised.
ImplDAO 1
HU 01
ImplDAO 8
Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/logging/BasicLogger
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:176)
at util.HibernateUtil.<clinit>(HibernateUtil.java:14)
at dao.impl.ImplDAO.setData(ImplDAO.java:27)
at service.MainClass.main(MainClass.java:17)
"HU 01" appears in console, "HU 02" doesn't. So, I think, I have got some hibernate.cfg.xml problems, but it's also made with manual:
<?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.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1251:XE</property>
<property name="hibernate.connection.username">SYSTEM</property>
<property name="hibernate.connection.password">12345</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="current_session_context_class">thread</property>
<mapping class="logic.EntityClass" />
</session-factory>
</hibernate-configuration>
My environement:
Hibernate 4.1
WebLogic Server 11gR1
Oracle DataBase 11g Express Edition
Eclipse Juno
JRE: jdk1.7.0_09
(same thing with Oracle WebLogic Server 11gR1 (10.3.2) JRE)
AnyIdea?
回答1:
It's not a Hibernate configuration problem. Your are missing a dependency : jboss-logging.jar. That's why your program cannot find the class org.jboss.logging.BasicLogger
回答2:
You're missing out one or more of the dependencies. This is how the dependency hierarchy looks like for one of my projects:

Make sure you have the required jars in the classpath of your application. If possible use maven. It does the dependency management for you, among a lot other things.
回答3:
you need jboss-logging-3.1.0.GA which comes with hibernate distribution or it can downloaded seperately.
来源:https://stackoverflow.com/questions/15022438/hibernate-configuration-troubles