SSH Integration Error: Org.hibernate.hql.internal.ast.QuerySyntaxException:User is not mapped[...]

Source: Internet
Author: User

Very strange error, the information is as follows:
Org.hibernate.hql.internal.ast.QuerySyntaxException:User is isn't mapped [select COUNT (*) from the User u where u.username=? an D u.userpassword=? ]
caused By:org.hibernate.hql.internal.ast.QuerySyntaxException:User is not mapped
Similar to the resolution of the error message, I also studied for half a day to finally find the problem
There are two types of errors that occur in this case

1, the configuration file is not loaded into Hibernate's entity list

2, the mapping file's fields are inconsistent with the database fields, or the name inconsistency causes

HQL is a special grammar. is not SQL. You set the Hibernate dialect to the database you use.
The syntax and HQL of SQL are not the same thing.
...... Querysyntaxexception ... Is that the SQL you want is not HQL, syntax error:

1. See if you forgot to add the hibernate mapping file to Hibernate.cfg.xml (when using hibernate) or Applicationcontext.xml

2. Check the fields in the table and whether the fields in the mapping file correspond to one by one

3. Check if the field name uses keywords from the database

4.HQL statement is correct

Hql:hibernate Query Language Hibernate is equipped with a very powerful query language that looks much like SQL. But instead of being fooled by the similarity in grammatical structures, HQL is very conscious of being designed as a fully object-oriented query that can understand concepts such as inheritance, polymorphism, and correlation.

So this time you have to carefully check your written HQL statement, must be the object query, especially "TableName" do not write the table you want to query, but the object of the query

Like what:

Public long Gettypecount (patent patent) {
String hqlstring = "SELECT count (*) from patent as P where P.type = '" +patent.gettype () + "'";
Query query = this.getsession (). CreateQuery (hqlstring);
Long Count = 0;
Count = ((number) Query.uniqueresult ()). Intvalue ();
return count;
}

Patent is an object

The database table name is patent if written as String hqlstring = "SELECT count (*) from Patent as P where P.type = '" +patent.gettype () + "'";

Certainly is the query does not produce the result, remember!

SSH Integration Error: Org.hibernate.hql.internal.ast.QuerySyntaxException:User is not mapped[...]

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.