Hibernate 中出现 users is not mapped 问题 (转)
Posted wEndu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Hibernate 中出现 users is not mapped 问题 (转)相关的知识,希望对你有一定的参考价值。
今天晚上自己试着用Hibernate去搭建一个Web工程,然后去实现一个简单的登录。
通过Hibernate 做查询操作的时候总是报出这样的错:
users is not mapped.
于是乎去检查了下映射,发现没问题呀,反复验证结果还是一样报错。
User.hbm.xml:
<class name="com.lian.bean.User" table="users">
hibernate.cfg.xml:
<mapping resource="com/lian/bean/User.hbm.xml" />
在网上找了很多,但还是不给力,大家都没提些有建设性的解决方案,基本上都是说配置有问题。
不过自己感觉是这个出问题:
String sql = "select u.password from users u where u.username=‘" +user.getUsername()+ "‘";
经过多番纠结和耐心查找资料,发现:
原来 HQL语句中表名应该是ORM映射的类名,所以应该改成:
String sql = "select u.password from User u where u.username=‘" +user.getUsername()+ "‘";
哈哈哈,在此给所有在初学Hibernate的过程中遇到类似问题的people!!!
以上是关于Hibernate 中出现 users is not mapped 问题 (转)的主要内容,如果未能解决你的问题,请参考以下文章