-->
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.  [ 4 posts ] 
Author Message
 Post subject: HQL question
PostPosted: Wed Jun 02, 2004 11:23 pm 
Newbie

Joined: Thu May 27, 2004 5:16 am
Posts: 4
I've read the documentation.
But I don't know to use HQL.

For example,
SQL:
"select * from account where account = '" + account "' and password = '" + password + "'"

HQL
Query query = session.createQuery("select account from Account account where account.account = '" + account + "' and accont.password = '" + password + "'");
But it doesn't work.

Any ideals?
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 1:10 am 
Newbie

Joined: Sat Aug 30, 2003 12:37 pm
Posts: 16
In Hibernate, you query using objects and properties instead of tables and columns. You wrote SQL not HQL.

Try the following code which uses named parameters:

String query = "from Account a where a.account=:account and a.password=:password";

Query q = session.createQuery(query);
q.setString("account", account);
q.setString("password",password);


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 1:17 am 
Newbie

Joined: Sat Aug 30, 2003 12:37 pm
Posts: 16
FYI, I am assuming that you have mapped Account Object to the Account table in your database. If not, then do that before trying the above example.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 3:08 am 
Newbie

Joined: Thu May 27, 2004 5:16 am
Posts: 4
Thanks!!


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