• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Newbie's question for Hibernate+MySQL

 
James Zhang
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
 
pascal betz
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!
 
Lasse Koskela
author
Sheriff
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic