Tomcat中配置Hibernate的一个问题
各位大侠帮帮忙啊,这个问题搞了好几天了,都不知道错在哪了。问题描述如下:
Tomcat中的MySQL数据库连接池安装正确,我自己测试过了
D:\program file\Tomcat 5.0\webapps\register
Hibernate目录\lib下的所有.jar文件已经全部复制到Tomcat安装目录下的\webapps\register\WEB-INF\lib中(包括hibernate3.jar),hibernate.cfg.xml和register.hbm.xml已经放入到WEB-INF\classes中,
MySQL中有一个数据库名为quickstart,其中表t_register的字段有id(主键) int型,username varchar型,password varchar型,sex varchar型,age int型
HibernateUtil.java的源文件如下:
package register;
import
org.hibernate.HibernateException;
import org.hibernate.cfg.*;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.*;
import java.io.*;
public class HibernateUtil{
private static final SessionFactory sessionFactory;
static{
try{
Configuration config=new Configuration().configure();
sessionFactory=config.buildSessionFactory();
}
catch(Throwable ex){
ex.printStackTrace();
System.out.println( "HibernateUtil出错 ");
throw new
ExceptionInInitializerError(ex);
}
}
public 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.java
package register;
public class Register{
private int id;
private String username;
private String password;
private String sex;
private int age;
public int getId()
{
return id;
}
public void setId(int id)
{
this.id=id;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username=username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.pass