• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Newbie's question for Hibernate+MySQL

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to use Hibernate 3.0 + MySQL for a demo application. However, I got a problem for the syntax of my query. A simple example would be to list all the event from Events table. From some tutorial, the following code would bring you all the events:

List result = session.createQuery("from events").list();

However, I always got exception saying checking syntax around "from" for SQL statement! Obviously MySQL doesn't like the syntax, but I could not use "select * from events" for my query either (Hibernate will complain this time).

Anyone has similar problem before?

Thanks!

James
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you do not query tables in hibernate. you kind of query for objects. so unless you have a class called "events" your HQL query is wrong. you need to specify the classname instead of the table. you should be able to write HQL queries without knowing anything about tables and columns the objects are mapped to.
try

instead.
or

you can also turn on loggin to show the generated SQL to see what SQL statements are created by hibernate. this can also help.

you can have a look at the HQL BNF to see if you have a valid query.

did that help ?

pascal
[ January 31, 2005: Message edited by: pascal betz ]
 
James Zhang
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much for the help, pascal! It is the problem!
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James, would you mind editing your display name a bit to include a last name? You see, our naming policy requires a full last name and only the first/middle name can be shortened to initials.

Thanks.
 
The two armies met. But instead of battle, they decided to eat some pie and contemplate this tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!