-->
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.  [ 5 posts ] 
Author Message
 Post subject: Why does the HQL-statement not work.
PostPosted: Tue Feb 17, 2004 8:10 am 
Newbie

Joined: Mon Feb 16, 2004 7:11 am
Posts: 13
Hello everybody!

I was trying to use the HQL language to select some objects from the database. My code looks like this:

Code:
Query q = session.createQuery("SELECT userrole FROM UserRole as userrole WHERE userrole.username = :username");
q.setString("username",username);


But this throws a javax.servlet.ServletException: unexpected token: as [SELECT userrole FROM UserRole as userrole WHERE userrole.username = :username] at me.

Why does it do that? Didn't I keep the query as simple as possible.
I tried to do the same with the Criteria-class and that works.

I'm dazzled.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 8:18 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
Remove the as keyword from your query and write it as follows:

Code:
SELECT userrole FROM UserRole userrole WHERE userrole.username = :username


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 8:25 am 
Beginner
Beginner

Joined: Tue Jan 27, 2004 2:14 pm
Posts: 40
Location: Atlanta, GA, USA
I'm not sure if this will help you but here are some suggestions...

    - Try Hibern8IDE (Inlcuded in the HibernateExtensions distribution)
    - Are you sure userrole.username shouldn't be userrole.userName ?
    - Are you sure the String username isn't null?
    - Turn DEBUG mode on in your loggng, also turn on the hibernate SQL.

Hope this helps.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 10:23 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You can use 'as'
Be sure that UserRole is mapped and that the file is referenced in hibernate.cfg.xml
Try the fully qualified class name.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 1:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hibernate does not know about the UserRole class.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.