• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate - Table Not Mapped

 
Ranch Hand
Posts: 193
14
Hibernate Eclipse IDE Spring
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 193
14
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Roel - that worked perfectly!
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:

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!



I signed up for the website to write you a thank you message .
Thank you.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:And another remark: you should use either Hibernate XML based mapping or JPA annotation based mapping, but not both.



This is not accurate. First, I'm gong to take "Hibernate XML based mapping" as referring to legacy Hibernate. If you are using JPA (including Hibernate JPA), don't expect legacy Hibernate XML to work. You need JPA XML.

Given that, when you have an annotation and an XML definition, the XML definition will override the annotation. The annotation serves as a default, while the XML is a way to override it without having to edit and re-compile the class, making the class more re-usable (and testable).

This convention of XML overriding annotations applied to other systems besides JPA. JavaServer Faces, for example. And the WEB-INF/web.xml file now that much of the original web.xml features can now be defined via annotations.
reply
    Bookmark Topic Watch Topic
  • New Topic