郁闷啊,运行Hibernate应用程序出现了一个怪问题:应用程序在Jbuilder2006中运行正常,但是打包发布到Tomcat5.5后却在登录验证时出现User is not mapped问题(测试后也发现不能映射其他对象),验证代码如下:
//在默认构造函数中已进行Session,Transaction等初始化,Transaction已开始
//整个应用程序在Jbuilder2006中运行正常,但打包发布在Tomcat5.5中运行到
//query = s.createQuery(sql);处就报错
public boolean checkLogin(User user)
{
try
{
String sql = "from User u where u.userName= ' " +user.getUserName()+ " ' ";
ps.println(sql) ;
query = s.createQuery(sql); //报错,产生User is not mapped异常
User myUser=(User)query.uniqueResult();
if(myUser!=null)
{
if (myUser.getUserPwd()!=null)
return myUser.getUserPwd().equals(user.getUserPwd());
else
return user.getUserPwd()==null;
}
}
catch (Exception e)
{
System.out.println( "select User Error: "+e.getMessage());
e.printStackTrace();
}
return false;
}
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 ">
<hibernate-configuration>
<session-factory>
<property name= "connection.url "> jdbc:microsoft:sqlserver://127.0.0.1:1433;databasename=MyData </property>
<property name= "dialect "> org.hibernate.dialect.SQLServerDialect </property>
<property name= "connection.username "> sa </property>