• 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

about Hibernate

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,everyone!
I use HQL to query the database in my program. Here is my code:



I have looked many source code about querying in hibernate, and I think my HQL query is nothing wrong. But when running, there is always


net.sf.hibernate.QueryException: unexpected token: as [select from userinfo as ui]


I am really confused. Please give me your advices if possible.

Thanks for help!

Have a nice day!

Regards,
 
George Ren
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, actually my code is:
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what's the exception you get with this new code?
 
George Ren
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the same exception. A paste the wrong code first time, the last code is actually the code I run, and got the exceptions above.
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The same exception? Even though your code doesn't use "select from userinfo as ui" in any query?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That error means you've an unrecognised word in your HQL. This could be because you've mapped userinfo wrong - check the mapping file, remeber it is case sensetive.

Also - you probably could do with getting rid of the nested try/catch blocks - they are unecessary, and make the code less clear.
 
George Ren
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think there's nothing wrong with the mapping. The table userinfo in database is created in program using Hibernate also. And below is my UserInfo class and the UserInfo.hbm.xml file:


 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember that with Hibernate you are qureying in HQL unless you specifically specify SQL. So:

is looking for all userinfo Objects in a Hibernate Session, not for the contents of the userinfo table. Are there any objects in the Session with that name? Well unless you've defined it elsewhere, then no. But there is a UserInfo.
 
George Ren
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks you to give me advises ,Lasse Paul. And finally I know what is wrong. I give the mapping name uncorrently.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic