• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate - Table Not Mapped

 
Simon Ritchie
Ranch Hand
Posts: 93
4
Eclipse IDE Hibernate Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm working with Hibernate for the first time but am having trouble executing a query against a table. My project is an Eclipse Maven Project that incorporates both Spring and Hibernate (I'm working off this tutorial). My Maven dependencies are all in good order and both my Spring Application Context file and Hibernate configuration file appear to be set up correctly. However when I try to query a table that I've mapped to a Java Bean I get the following error

Exception in thread "main" org.hibernate.hql.ast.QuerySyntaxException: MY_SCHEMA.TEST_TABLE_SR is not mapped [FROM MY_SCHEMA.TEST_TABLE_SR]

This is my Hibernate configuration file



This is the Java Bean that I've mapped to the table



This is the DAO implementation class I'm using to query the data



And this is the Spring configuration file



From what I can see I have mapped the table to the bean correctly so I don't understand why I'm getting a message saying otherwise?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simon Ritchie wrote:From what I can see I have mapped the table to the bean correctly so I don't understand why I'm getting a message saying otherwise?

In JPQL (or HQL), you must use the Java class name and property names of the mapped @Entity instead of the actual table name and column names. So the JPQL (or HQL) should be:And another remark: you should use either Hibernate XML based mapping or JPA annotation based mapping, but not both. So in your @Entity class you have used JPA annotations to map your class to the database table, so you can get rid of the Hibernate configuration file.

Hope it helps!
Kind regards,
Roel

PS. Have a cow for such an excellent post! Using code tags for the different code snippets, a clear description of what you are trying to do and which error(s) you are facing. Well done!
 
Simon Ritchie
Ranch Hand
Posts: 93
4
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Roel - that worked perfectly!
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to hear it worked like a charm!

As you are a Hibernate (and JPA) newbie, the Java Persistence API WikiBook will probably be very useful to you. When I'm having an issue with JPA, JPQL, or something related it's the first resource I'll check to find a solution. It's really an excellent resource (in my humble opinion)! It's not a step-by-step tutorial, but you'll find everything required in this wiki book: from basic entity mappings to complex JPQL queries.

If you are looking for a step-by-step tutorial, I would definitely have a look at the Hibernate Getting Started Guide.

Hope it helps!
Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic