SSH integration error: org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped[……]

Very strange error, the information is as follows: 
org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped [select count(*) from User u where u.userName=? and u.userPassword=?] 
Caused by: org .hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped 
similar error message solution, I also studied for a long time before finally discovering the problem
There are two kinds of error conditions: 

1. The configuration file is not loaded into the hibernate entity list. 

2. The fields of the mapping file are inconsistent with the database fields, or the names are inconsistent, resulting 

in a special syntax for hql. Not sql. You set the hibernate dialect to the database you use.
The syntax of sql and hql are not the same thing. 
......QuerySyntaxException... means that the sql you want is not hql, and the syntax is wrong. .

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

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

3. Check whether the field name uses keywords in the database

4. Is the HQL statement correct?

HQL: Hibernate query language Hibernate is equipped with a very powerful query language that looks a lot like SQL. But don’t be fooled by the similarities in grammatical structure, HQL is very consciously designed as a fully object-oriented query, it can understand concepts such as inheritance, polymorphism, and association.

 

So at this time you have to carefully check the hql statement you write, it must be an object query, especially [tableName] Do not write the table you want to query, but the object of the query

such as:

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 it is written as String hqlString = “select count(*) from p atent  as p where p.type ='”+patent.getType()+”‘”; 

There must be no results from the query, remember!

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *