求助各位大侠,项目使用Struts1.2+Hibernate3.3来做的。之前部署使用完全没有问题。最近由于项目需要,又添加了几个数据表,同时添加了相应的entity和.hbm.xml文件,并且在hibernate.cfg.xml中添加了相应的记录。结果,系统就bug掉了。报错为: java.lang.NoClassDefFoundError.couldn't initialize class HibernateUtil
HibernateUtil是读取hibernate.cfg.xml文件的类。但是如果在hibernate.cfg.xml中删掉新添加的数据表记录,系统正常工作;在线等啊~~~~急!附代码如下:
1. HibernateUtil.java; 2. hibernate.cfg.xml 3. jar包截图 1. HibernateUtil.javapackage com.usensor.hibernate.util;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;public class HibernateUtil {
private static SessionFactory sessionFactory;
public HibernateUtil(){}
static{
Configuration cfg = new Configuration();
cfg.configure();//cfg.configure("Hibernate.cfg.xml"),用于读取配置文件
sessionFactory = cfg.buildSessionFactory(); }
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public static Session getSession(){
return sessionFactory.openSession();
}
public static void closeSession(Session session){
if(session!=null){
if(session.isOpen())
session.close();
}

}

}2. 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="proxool.pool_alias">proxoolPool</property>
<property name="proxool.xml">WEB-INF/proxoolconf.xml</property>
<property name="hibernate.proxool.existing_pool">true</property>
<property name="connection.provider_class">
org.hibernate.connection.ProxoolConnectionProvider
</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.characterEncoding">UTF-8</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="connection.url"></property>
<mapping resource="com/usensor/user/entity/UsrUser.hbm.xml" />
<mapping resource="com/usensor/user/entity/UsrAdmin.hbm.xml" />
<mapping resource="com/usensor/feed/entity/FeedInfo.hbm.xml" />
<mapping resource="com/usensor/feed/entity/FeedDatastream.hbm.xml" />
<mapping resource="com/usensor/feed/entity/FeedData.hbm.xml" />
<mapping resource="com/usensor/utils/entity/MngNotice.hbm.xml" />
<mapping resource="com/usensor/user/entity/UsrFavfeed.hbm.xml" />
<mapping resource="com/usensor/user/entity/UsrMsg.hbm.xml" />
<mapping resource="com/usensor/utils/entity/Searchkey.hbm.xml" />
<mapping resource="com/usensor/feed/entity/FeedTriggers.hbm.xml" />
<mapping resource="com/usensor/user/entity/UsrPubfeed.hbm.xml" />
<mapping resource="com/usensor/app/entity/MngApplication.hbm.xml" />
<mapping resource="com/usensor/feed/entity/MngRecfeed.hbm.xml" />
<mapping resource="com/usensor/utils/entity/ContactUs.hbm.xml" />
<mapping resource="com/usensor/feed/entity/DelDataBackup.hbm.xml" />
<mapping resource="com/groupus/entity/Group.hbm.xml" />
<mapping resource="com/groupus/entity/Message.hbm.xml" />
<mapping resource="com/groupus/entity/Member.hbm.xml" />
<mapping resource="com/usensor/classify/entity/AppSrt.hbm.xml" />
<mapping resource="com/usensor/classify/entity/UsrCls.hbm.xml" />
        <!-- 以下五条是新添加的-->
<mapping resource="com/usensor/archi/entity/Area.hbm.xml" />
<mapping resource="com/usensor/archi/entity/Architecture.hbm.xml" />
<mapping resource="com/usensor/archi/entity/ArchiInfo.hbm.xml" />
<mapping resource="com/usensor/archi/entity/PicInfo.hbm.xml" />
<mapping resource="com/usensor/archi/entity/RouteInfo.hbm.xml" /></session-factory></hibernate-configuration>3. jar包截图

解决方案 »

  1.   


    新的entity和.hbm.xml都是我自己手写的,但是hibernate.cfg.xml中的新纪录是自动生成的。
      

  2.   


    新的entity和.hbm.xml都是我自己手写的,但是hibernate.cfg.xml中的新纪录是自动生成的。自动生成试试
      

  3.   

    java.lang.NoClassDefFoundError.couldn't initialize class HibernateUtil看你写的也没错啊,是不是HibernateUtil的路径有问题呢?
      

  4.   

    把tomact work和webapps包中的项目目录删除,重新启动tomact编译
      

  5.   

    回复于: 2013-06-21 13:54:19 java.lang.NoClassDefFoundError.couldn't initialize class HibernateUtil
     
    看你写的也没错啊,是不是HibernateUtil的路径有问题呢? 
      

  6.   

    结贴结贴 被自己的2B错误雷到了还是图样图深破。是有一个entity中的属性名字写错了 导致和.hbm.xml中的属性名字对应不上 于是就导致了上面那个挨不着边的错误。散分了