首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

hibernate-3.2.5.ga 报java.lang.ExceptionInInitializerError是什么原因

2011-11-10 
hibernate-3.2.5.ga 报java.lang.ExceptionInInitializerError是什么原因?各位大侠,这几天按照网上的介绍,

hibernate-3.2.5.ga 报java.lang.ExceptionInInitializerError是什么原因?
各位大侠,这几天按照网上的介绍,在Eclpse环境里面,作了个简单的Hibernate例子,运行,但是报错:java.lang.ExceptionInInitializerError,具体的代码以及配置文件如下:

 hibernate.cfg.xml配置内容:
 <?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">

<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">CBS</property>
<property name="connection.url">
jdbc:oracle:thin:@localhost:1521:CBSTJ
</property>
<property name="dialect">
net.sf.hibernate.dialect.OracleDialect
</property>
<property name="jdbc.fetch_size">50</property>
<property name="jdbc.batch_size">25</property>
<property name="show_sql">true</property>
<property name="use_outer_join">false</property>
<property name="connection.password">admin</property>
<property name="connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<mapping resource="TRegister.hbm.xml"/>
 
</session-factory>
</hibernate-configuration>

TRegister.hbm.xml的内容:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
<hibernate-mapping>
<class name="hibernate.PO.TRegister" table="t_register">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="increment" />
</id>
<property name="userName" type="java.lang.String">
<column name="userName" length="30" />
</property>
<property name="userPwd" type="java.lang.String">
<column name="userPwd" length="30" />
</property>
<property name="sex" type="java.lang.String">
<column name="sex" length="10" />
</property>
<property name="age" type="java.lang.Integer">
<column name="age" />
</property>
</class>
</hibernate-mapping>
配置文件都放在classes下面。


 HibernateUtil.java获取唯一Session实例:

 package hibernate;
 
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil{
   
  private static final SessionFactory sessionFactory;
   
  static
  {
  try
  {
  Configuration config = new Configuration().configure("/hibernate.cfg.xml");
   
  sessionFactory = config.buildSessionFactory();
  }
  catch(Throwable e)
  { System.out.println("ExceptionInInitializerError----------" );
  throw new ExceptionInInitializerError(e);
  }
  }
   


  public static final ThreadLocal session = new ThreadLocal();
   
  public static Session currentSession() throws HibernateException
  {  
  Session s = (Session)session.get();
   
  //Open a new Session,if this Thread has none yet
  if(s == null || !s.isOpen())
  {  
  s = sessionFactory.openSession();  
  session.set(s);
  }
  return s;
  }
   
  public static void closeSession() throws HibernateException
  {
  Session s = (Session)session.get();
  session.set(null);
  if(s != null)
  s.close();
  }

}

 当运行到:sessionFactory = config.buildSessionFactory()时,就报上面那个错java.lang.ExceptionInInitializerError。
 我在工程的LIB下面,我把hibernate-3.2.5.ga.tar.gz里面的JAR都已经放进去(包括hibernate3.jar),构建路径当然也已经指向\WEB-INF\lib了,但是还是报错,是什么原因呢?
 


[解决办法]
搞定了,原因:
1、配置文件的 net.sf.hibernate.dialect.OracleDialect 应该写为org.hibernate.dialect.OracleDialect;
2、把LIB下面所有JAR删掉,然后再把需要的JAR全部拷贝进去

热点排行