专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Java Exception

hibernate-3.2.5.ga 当运行到:sessionFactory = config.buildSessionFactory()时,就报上面那个错java.lang.ExceptionInI

发布时间:2010-06-05 12:36:03 文章来源:www.iduyao.cn 采编人员:星星草

在Eclipse环境里面,作了个简单的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();      

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: