• 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 QuerySyntaxException with MySql

 
Greenhorn
Posts: 12
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I'm using hibernate to connect MySQL DB, I made a persistence-unit like below and added my class in it:



in my config file, I made an entity manager factory bean and added the data source in it:



The person class in an entity and a table.

now... when I wanna run this Query, I see an exception:



the exception is:

org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: * near line 1, column 8 [SELECT * FROM com.example.domain.Person P WHERE P.userName = UserName]




my Query is right.. why I see this exception?!

I changed my Query to this:



then I saw this:

org.hibernate.QueryException: could not resolve property: FirstName of: com.example.domain.Person [SELECT P.userName, P.password, P.FirstName, P.LastName FROM com.example.domain.Person P WHERE P.userName = UserName]



my domain class is:



what should I do?! please help me
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Selecting all properties
You cannot use the * operator in HQL (you are using HQL here, not SQL). Instead of

Use

or


Query parameters
Instead of simply using "Username" in your query, you need to use ":Username"
 
Shadi Mehrabadi
Greenhorn
Posts: 12
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh... Thanks James

I'm on it for two days,

when I read your post, I found this for the HQL,

http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html


I didn't know it's name

thanks man,
 
James Boswell
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shadi

Be sure to use the reference guide that matches your version of Hibernate. That one is for 3.3.
reply
    Bookmark Topic Watch Topic
  • New Topic