• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

How to Solve QuerySyntaxException in Hibernate?

September 26, 2015 //  by Krishna Srinivasan//  Leave a Comment

If you are working on hibernate, getting QuerySyntaxException is very common if there is any issue with the query which you are trying to execute in your code. This QuerySyntaxException is more generic and it would throw different types of error messages based on the issue with the query. In this post I would update my experience on getting the different type of messages and how I have solved them.

QuerySyntaxException : Table is not mapped

I have encountered this exception while using the HSQL databases for running my Spring Data application using Spring Boot. Also this error thrown at the time of using the query methods to write the query in spring data repository.

  • Error Message: org.hibernate.hql.internal.ast.QuerySyntaxException: $$table_name$$ user is not mapped [$$query_string$$]
  • Problem: This problem occurs only when the table name you have mentioned in the query is not matching with the entity.
  • Solution: The table name used in the query is not the one in the real database, it should be the name of the entity class. If you are trying to map to the database table and actual entity class name is different, it would throw this error. Also note that the query string should have the exact case (Uppercase or Lowercase) of the entity class name to work properly.
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: user is not mapped [select username from user u where u.username = ?1]
	at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:96)
	at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:120)
	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:234)
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: user is not mapped
	at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:189)
	at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:109)
	at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:95)

I hope this solution would solve your problem. Still you have not solved, please post your exception trace in the comments section.

Category: HibernateTag: Hibernate Exceptions

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: «java Default Keyword in Java
Next Post: @Query Annotation in Spring Data JPA spring data jpa»

Reader Interactions

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact