-->
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.  [ 2 posts ] 
Author Message
 Post subject: Query/createQuery() usage with setXXX() methods
PostPosted: Wed Sep 24, 2003 3:43 pm 
Newbie

Joined: Wed Sep 17, 2003 1:31 am
Posts: 7
Location: tampa, FL
Make sure to use a 0 based value as the first parameter in the setXXX() methods used on the Query object when setting parameterized values instead of being 1 based.

Example:
Query query = session.createQuery(" from Widget as widget where widget.persistence = ? " );

setString( 1, "hibernate" ); //hibernate does not like you
setString( 0, "hibernate" ); //hibernate likes you

If this doesn't help anyone please disregard. The logs didn't do much to point to the mistake.

regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2003 8:36 am 
Regular
Regular

Joined: Tue Aug 26, 2003 3:09 pm
Posts: 58
I feel alot safer using named parameters instead. I would recommend using named parameters if possible. Some advantages include being self-documenting, and not as prone to errors related to the position of the parameter in the query.

Example:
Query query = session.createQuery(" from Widget as widget where widget.persistence = :persistence " );

setString( "persistence", "hibernate" ); //hibernate likes you


Joe


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