Hibernate初级问题 常量是可以在sastic初始化 但是可能是你的hibernate配置出问题 所以没有初始化成功 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你的配置文件是什么类型的?properties还是XML类型的?如果是前者应该还需要加载ORM文件。 你的hibernate.hbm.xml或者是mapping文件的错误. 现在问题有了点发展,上面的问题是代码写的有误,现重新编排一下问题:在register.jsp(入口文件)输入信息,抛出ExceptionInInitializerError异常,Tomcat控制台出现的部分重点错误如下:hibernate.properties nou found(我用的是hibernate.cfg.xml)configuring from resource: /hibernate.cfg.xmlMapping 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>不知道我说的是否够清楚,望兄弟们能帮我看看,搞了一天了,郁闷 集合带泛型删除另个集合里相同(重复实体) 菜鸟 求解决java的tcp问题 关于java,面向对象的疑惑 JSP中红叉怎么去掉 在server端的java代码中,如何获取客户端的上一个URL? 高分请教jasperReport问题。问题解决,立即给分 分页显示问题,向高手请教!! 怎样用jbuilder和weblogic部署sun公司的petstore? java调用.net webservice服务参数返回是空 删除 console configuration文件 如何使lucene全文检索到的结果在jsp页面上高亮显示? Struts上传问题,请高手帮忙,谢谢!
在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>
不知道我说的是否够清楚,望兄弟们能帮我看看,搞了一天了,郁闷