-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Been Doing My Nut!!! HQL Syntax Problem
PostPosted: Fri Mar 26, 2010 11:11 am 
Newbie

Joined: Fri Mar 26, 2010 11:00 am
Posts: 2
Hi All,
Been trying to figure this for a few days now, I must be missing something on the config side of things.
Im using netbeans to create a simple login form which looks at a MySQL table Users. I followed the tutorial on the netbeans website to create the Hibernate config file, reverse engineer, pojos and mapping files, etc.
Im having a problem that when i try to run HQL it fails with a syntax error:
------------------------
javax.servlet.ServletException: org.hibernate.exception.SQLGrammarException: could not execute query
------------------------
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from Users' at line 1
------------------------

the code i am tying to run is a simple from command :

org.hibernate.Query query = session.createSQLQuery("from Users'");
userList = (List<Users>) query.list();

This works if I change to sql statement to "Select * From Users", but it will not recognise it as a list of Users. It seems to me like it can recognise SQL but not HQL.

Any help would be greatly appreciated

Alex


Top
 Profile  
 
 Post subject: Re: Been Doing My Nut!!! HQL Syntax Problem
PostPosted: Fri Mar 26, 2010 12:40 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
session.createSQLQuery() is for SQL queries and session.createQuery() is for HQL queries. Change your code to use the latter and it should work.


Top
 Profile  
 
 Post subject: Re: Been Doing My Nut!!! HQL Syntax Problem
PostPosted: Fri Mar 26, 2010 12:49 pm 
Newbie

Joined: Fri Mar 26, 2010 11:00 am
Posts: 2
ahh so simple, how did i not see this! Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.