首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

org.hibernate.hql.ast.QuerySyntaxError: User is not mapped解决方法!

2014-01-26 
郁闷啊,运行Hibernate应用程序出现了一个怪问题:应用程序在Jbuilder2006中运行正常,但是打包发布到Tomcat5.

郁闷啊,运行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>
  <property name= "connection.password "> sa </property>
<property name= "connection.driver_class "> com.microsoft.jdbc.sqlserver.SQLServerDriver </property>
  <property name= "hibernate.show_sql " > true </property>
  <property name= "current_session_context_class "> thread </property>
<mapping resource= "User.hbm.xml "/>         

热点排行