常量是可以在sastic初始化 
但是可能是你的hibernate配置出问题 所以没有初始化成功

解决方案 »

  1.   

    你的配置文件是什么类型的?properties还是XML类型的?如果是前者应该还需要加载ORM文件。
      

  2.   

    你的hibernate.hbm.xml或者是mapping文件的错误.
      

  3.   

    现在问题有了点发展,上面的问题是代码写的有误,现重新编排一下问题:
    在register.jsp(入口文件)输入信息,抛出ExceptionInInitializerError异常,Tomcat控制台出现的部分重点错误如下:
    hibernate.properties nou found(我用的是hibernate.cfg.xml)
    configuring from resource: /hibernate.cfg.xml
    Mapping resource: /register.hbm.xml
    ....
    Configured SessionFactory: null(我认为这是关键)
    ....以上我感觉是SessionFactory对象没得到吧,HibernateUtil.java(编译已经成功)全代码如下:
    public class HibernateUtil
    {
       private static final SessionFactory sessionFactory;
       static
       {
         try{
    Configuration config=new Configuration().configure();
    sessionFactory=config.buildSessionFactory();
         }catch(Throwable ex){
    ex.printStackTrace();
    throw new ExceptionInInitializerError(ex);
         }
       }

       private static final ThreadLocal session=new ThreadLocal();
       public static Session currentSession() throws HibernateException
       {
    Session s=(Session)session.get();
    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();
        }
    }不过我还感觉可能register.hbm.xml书写也有错误,全代码如下:
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

    <hibernate-mapping> <class name="register.Register" table="t_register">

    <id name="id">
    <generator class="increment"/>
    </id>

    <property name="username" column="username" type="string"/>
    <property name="password" column="password" type="string"/>
             <property name="sex" column="sex" type="string"/>
    <property name="age" column="age" type="int"/>

             </class></hibernate-mapping>
    不知道我说的是否够清楚,望兄弟们能帮我看看,搞了一天了,郁闷