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:
- MyBatis: Mapped Statements collection does not contain value for xxx
- Solution of Hibernate paging report only entering result set and not supporting requested operation
- Android Error:Internal error:org.gradle.tooling.BuildException: Could not execute build…
- Eclipse Install Hibernate Error: An internal error occurred during: “Initializing Eclipse Error Reporting System
- [Solved] Mybatis-plus Error: mybatisplus-Invalid bound statement (not found): com.integration.dao.ApiDao.getList
- [vite] Internal server error:options.devServer.transformWidthEsBuild is not a function…
- [Solved] Rancher Add User Error: x509: certificate has expired Internal error occurred: failed calling webhook “rancherauth.cattle.io”:
- [Solved] org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin
- Android integration of iFLYTEK’s speech recognition (voice dictation) error message “Failed to create the object, please confirm that libmsc.so is placed correctly, and createUtility is called to initialize”
- [Solved] Idea 2020 uses SVN error: ‘C: \ program’ is not an internal or external command
- [Solved] error: value createSchemaRDD is not a member of org.apache.spark.sql.SQLContext
- Abnormal [System.InvalidOperationException: custom type mapping for ‘xxx’ is not specified or is not a solution
- [INS-06006] Passwordless SSH connectivity not set up [Solved]
- The application could not be installed: INSTALL_FAILED_USER_RESTRICTED
- Tensorflow Run Error or the interface is stuck or report error: Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
- [Solved] SpringBoot integration with Redis error: java.net.ConnectException: Connection refused: no further information
- How to Solve org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) Error
- [Solved] MongoDB Update User Error: Error: not authorized on admin to execute command
- [Solved] Flink jdbc Error: Access Denied for user ‘root‘@‘10.0.0.x‘ (using password: YES)
- [Solved] Error getting ssh command ‘exit 0‘ : ssh command error: