MyException - 我的异常网
当前位置:我的异常网» Java相关 » hibernate-3.2.5.ga 报java.lang.ExceptionInInitia

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

www.MyException.Cn  网友分享于:2013-11-11  浏览:12641次
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);
  }
  }
   

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有