2012-12-27 38 views
2

我正在开发一个Hibernate项目,并且我配置了一切。在创建休眠配置中的java.lang.ExceptionInInitializerError

因此,我生成了beans和hbm文件。

于是,我写了一个测试类测试项目(我用的Client类)

当我执行的代码,以下异常被抛出:

java.lang.ExceptionInInitializerError 
Caused by: java.lang.NullPointerException 
at org.slf4j.LoggerFactory.singleImplementationSanityCheck(LoggerFactory.java:192) 
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:113) 
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:269) 
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242) 
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:255) 
at org.aness.test.HiberM.<clinit>(HiberM.java:12) 
Exception in thread "main" 

代码:

import org.aness.beans.*; 
import org.hibernate.Session; 
import org.hibernate.SessionFactory; 
import org.hibernate.Transaction; 
import org.hibernate.cfg.Configuration; 
import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 

public class HiberM { 
final static Logger logger = LoggerFactory.getLogger(Client.class); 
public static void main(String[]arg){ 

    Configuration cfg = new Configuration().configure(); 
    SessionFactory sf =cfg.buildSessionFactory(); 
    Session s = sf.openSession(); 
    Transaction tx =s.beginTransaction(); 

    Client c =new Client(); 
    c.setRaisonSociale("peugeot algerie"); 
    c.setNumeroRc("3215468897"); 
    c.setIdentificationFiscale("888777999"); 
    c.setAdresseActivite("blida zone atlas"); 
    c.setTelephone("00213(0)25436996"); 
    c.setFax("00213(0)25436996"); 

    s.save(c); 
    tx.commit(); 

    } 

} 

这就是整个问题。

休眠CFG文件是:*

<?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 name="apurement"> 
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
<property name="hibernate.connection.password">root</property> 
<property name="hibernate.connection.url">jdbc:mysql://localhost/apurement</property> 
<property name="hibernate.connection.username">root</property> 
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 
</session-factory> 
</hibernate-configuration> 

客户映射为:

<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
<!-- Generated 27 d?c. 2012 11:47:54 by Hibernate Tools 3.4.0.CR1 --> 
<hibernate-mapping> 
    <class name="org.aness.beans.Client" table="client" catalog="apurement"> 
    <id name="clientId" type="int"> 
     <column name="client_id" /> 
     <generator class="assigned" /> 
    </id> 
    <property name="raisonSociale" type="string"> 
     <column name="raison_sociale" length="150" not-null="true" /> 
    </property> 
    <property name="numeroRc" type="string"> 
     <column name="numero_rc" length="45" not-null="true" /> 
    </property> 
    <property name="identificationFiscale" type="string"> 
     <column name="identification_fiscale" length="45" not-null="true" /> 
    </property> 
    <property name="adresseActivite" type="string"> 
     <column name="adresse_activite" length="250" not-null="true" /> 
    </property> 
    <property name="adressePersonelle" type="string"> 
     <column name="adresse_personelle" length="250" /> 
    </property> 
    <property name="telephone" type="string"> 
     <column name="telephone" length="45" not-null="true" /> 
    </property> 
    <property name="fax" type="string"> 
     <column name="fax" length="45" not-null="true" /> 
    </property> 
    <set name="domiciliations" table="domiciliation" inverse="true" lazy="true" fetch="select"> 
     <key> 
      <column name="client_id" not-null="true" /> 
     </key> 
     <one-to-many class="org.aness.beans.Domiciliation" /> 
    </set> 
    </class> 
</hibernate-mapping> 
+0

请发布您的hibernate.cfg.xml和您的Client.hbm.xml文件。另外,你使用的是哪个Hibernate版本? – Vrushank

+0

你有一个hibernate.cfg.xml文件吗?你尝试过不同版本的slf4j吗? – theMarceloR

回答

1

的版本,我想你已经打了this issue

看来你正在使用SLF4J版本1.5.8(或其附近),因为source code of org.slf4j.LoggerFactory with tag 'SLF4J_1.5.8'的行号与你的堆栈跟踪中的行号相匹配。

我会建议更新到更高版本的SLF4J。

+0

我做过但没有任何事情 –

+0

@AnisBouchenafa:你现在使用哪个版本的SLF4J? –

2

两种可能性:

Hibernate.cfg.xml不在类路径中。它在哪个文件夹中?

否则,您可以尝试更新slf4j罐子