-->
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.  [ 6 posts ] 
Author Message
 Post subject: Problems with parameter binding to a Query
PostPosted: Thu Jan 22, 2004 6:37 am 
Beginner
Beginner

Joined: Thu Jan 22, 2004 6:16 am
Posts: 40
Location: Luxembourg
I'm a REAL newbie to Hibernate, so I need som basic help.
This is my Java code :

session = stack.getMessage().getTrans().getDBConnection();
hql = session.createQuery("SELECT f FROM com f WHERE f.id = :name" );
System.out.println("DETAIL : " + msg.getDetail ("container.in.id" ));
hql.setParameter(":name", msg.getDetail ( "container.in.id" ));
System.out.println("HQL : " + hql.getQueryString());

And the output I get is :

DETAIL : 4028fb7a
HQL : SELECT f FROM com.abpro.babel.CommsIn f WHERE f.id = :name

Where I had expected the result from
hql.getQueryString as :

HQL : SELECT f FROM com.abpro.babel.CommsIn f WHERE f.id = 4028fb7a

Could someone please help me with the correct way of binding
a value to a parameter, because the :name is not replaced by 4028fb7a
as I want ?

Regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 6:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
hql.setParameter(":name", msg.getDetail ( "container.in.id" ));

should be

hql.setParameter("name", msg.getDetail ( "container.in.id" ));


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 7:07 am 
Beginner
Beginner

Joined: Thu Jan 22, 2004 6:16 am
Posts: 40
Location: Luxembourg
Hmm strangely, this gives the same result. Do You have any other suggestions ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 7:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
hql.getQueryString does not give you the SQL acutally executed but the String you defined with createQuery(). Enable Hibernate SQL logging and check the log.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 12:06 pm 
Beginner
Beginner

Joined: Thu Jan 22, 2004 6:16 am
Posts: 40
Location: Luxembourg
Actually, the problem was the hql-query :

hql = session.createQuery("SELECT f FROM com f WHERE f.id = :name" );

should have been

hql = session.createQuery("SELECT f FROM com f WHERE f.id = ':name'" );

with single quotes around the :name.

I don't really know if this is right though, I don't get any exceptions,
but I can't see the replaced value of :name, in the Hibernate logging.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 12:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
no, you should never put quotes around a parameter


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