org.hibernate.hql.internal.ast.QuerySyntaxException: users is not mapped

来源:互联网 发布:dota2看视频软件 编辑:程序博客网 时间:2024/06/05 22:52

struct2和hibernate框架的学习果然是一波三折啊  错误不断 而且还找不到答案

User实体类

package com.scx.entity;public class Users {private int uid;private String username;private String password;public Users(int uid, String username, String password) {this.uid = uid;this.username = username;this.password = password;}public Users() {}public int getUid() {return uid;}public void setUid(int uid) {this.uid = uid;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}}

Users.hbm.xml

<hibernate-mapping>    <class name="com.scx.entity.Users" table="USERS" catalog="studentmanagent">        <id name="uid" type="java.lang.Integer">            <column name="UID" />            <generator class="native" />        </id>        <property name="username" type="string">        <column name="USERNAME" length="30"></column>        </property>        <property name="password" type="string">        <column name="PASSWORD" length="30"></column>        </property>         </class></hibernate-mapping>

我的hql语句

hql = "from users  where username = ? and password = ?";
使用junit测试的时候 总是报org.hibernate.hql.internal.ast.QuerySyntaxException: users is not mapped 

字面意思好像就是users没有映射  可是我明明配置的有啊   卡了很久 

于是就开始修改hql语句了   大小写各种互换  一次偶然机会 让我找到了  

修改为

hql = "from Users  where username = ? and password = ?";
仅仅修改了users为Users  就正确了  或许在hql中  对应的不是表名  应该是hbm.xml的文件名。。仅仅猜测。




1 0
原创粉丝点击