-->
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.  [ 3 posts ] 
Author Message
 Post subject: Query.setParameter(String , Object) not setting
PostPosted: Thu Mar 24, 2011 4:03 am 
Newbie

Joined: Thu Mar 24, 2011 3:56 am
Posts: 2
First and foremost i would like to say hi to everyone in this forum,

Coming to the point:

I am using the hibernate's Query class to create a query for database access. In the query i have a gender field which recieves the value dynamically on runtime. I am using the code :

if(gender != null) {
query = query.setParameter("gender", gender);
countQuery = countQuery.setParameter("gender", gender);
}


which is supposed to set the parameter. In Eclipse, if i debug through the code, gender has the value 'Male' or 'Female', but the Query will still be showing it as gender.

Can anyone please explain why this is happening and how i can resolve the issue.

Thanks in advance


Top
 Profile  
 
 Post subject: Re: Query.setParameter(String , Object) not setting
PostPosted: Thu Mar 24, 2011 4:25 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I guess you'll at least need to post your query (HQL) as well. What do you mean with but the Query will still be showing it as gender?


Top
 Profile  
 
 Post subject: Re: Query.setParameter(String , Object) not setting
PostPosted: Thu Mar 24, 2011 10:14 am 
Newbie

Joined: Thu Mar 24, 2011 3:56 am
Posts: 2
nordborg wrote:
I guess you'll at least need to post your query (HQL) as well. What do you mean with but the Query will still be showing it as gender?


gender is an Enum class and though the value of gender shows as "Male" or "Female", after the setParameter() is executed the query still showed

d.gender = :gender



Admin please close the topic as i resolved the issue myself..

all i had to do was change gender to gender.name()
if(gender != null) {
query = query.setParameter("gender", gender.name());
countQuery = countQuery.setParameter("gender", gender.name);
}


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