-->
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: setParameter/setInteger on query doesn't, so query fails
PostPosted: Tue Aug 08, 2006 5:03 pm 
Regular
Regular

Joined: Mon Aug 07, 2006 6:22 pm
Posts: 67
Using Hibernate 3.0.5, Spring 1.2.1, and JDK 1.4.2.

I've built a query that takes a single integer parameter. I've tried calling "query.setParameter()" and "query.setInteger()", but when I call "query.list()", it always fails with the following exception message (elided):

Hibernate operation: could not execute query; bad SQL grammar [select fieldconst0_.OID as OID, fieldconst0_.MODEL_VERSION as MODEL2_2_, [deleted]
fieldconst0_.REQUIRED as REQUIRED2_ from FIELD_CONSTRAINTS fieldconst0_ where (modelVersion=? )]

What I can see from this is that my call to "setParameter()" or "setInteger()" didn't change the resulting query, perhaps because it didn't find the parameter I was specifying.

I also see that when it translated from the HQL query to SQL, it didn't change "modelVersion" in the where clause to "MODEL_VERSION".

If I plug the resulting SQL into my SQL browser, change "modelVersion" to "MODEL_VERSION" and set the value to "1", the query works.

My original "queryHQL" is:

"from com.wamu.uia.riskrating.dao.FieldConstraint fieldConstraint where modelVersion=:modelVersion"

An excerpt of my hibernate-mapping file is as follows:

<class name="com.wamu.uia.riskrating.dao.FieldConstraint"
table="FIELD_CONSTRAINTS">
<id name="oid">
<column name="OID"/>
<generator class="increment"/>
</id>
<property name="modelVersion">
<column name="MODEL_VERSION"/>
</property>
[deleted]
<property name="required">
<column name="REQUIRED"/>
</property>
</class>

An excerpt from my code:

------------------
Query query = session.createQuery(getQueryHQL());
String[] namedParameters =
query.getNamedParameters();
if (strInArray(RiskRating.MODEL_VERSION, namedParameters))
{
query.setInteger(RiskRating.MODEL_VERSION,
modelVersion.intValue());
List results = query.list();
------------------

The value of "RiskRating.MODEL_VERSION" is "modelVersion". Note that I verify that string is one of the named parameter of the query before I try to set the value.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 11:23 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
If there is an alias you has to use it:

Code:
"from com.wamu.uia.riskrating.dao.FieldConstraint fieldConstraint where fieldConstraint.modelVersion = :modelVersion"


Don't forget to rate my answers if they are useful.


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.