Table name (XXX) is not mapped problem in Hibernate

Source: Internet
Author: User

Try it yourself tonight.Hibernate to build a Web project and then go for a simple login.
This is always the case when you do a query through Hibernate:
Users is?not?mapped.
So to check the next mapping, found no problem ah, repeated verification results are the same error.
User.hbm.xml:
<class name= "Com.lian.bean.User" table= "Users" >
Hibernate.cfg.xml:
<mapping resource= "Com/lian/bean/user.hbm.xml"/>
On the internet to find a lot, but still do not give force, we did not mention some constructive solutions, basically said configuration has a problem.
But I feel like this is a problem:
String sql = "Select U.password from Users u where u.username= '" +user.getusername () + "'";
After a lot of tangled and patient looking for information, found:
The table name in the original HQL statement should be the class name of the ORM map, so it should be changed to:
String sql = "Select U.password from User u where u.username= '" +user.getusername () + "'";
The SQL statement looks for the generated user class, not the normal table .....

Table name (XXX) is not mapped problem in Hibernate

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.