-->
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.  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: sqlquery.setParameter(int, object) can not guess java string
PostPosted: Mon Oct 16, 2006 1:02 pm 
Newbie

Joined: Mon Oct 16, 2006 10:36 am
Posts: 14
Location: Fort Worth, TX
DB: Oracle 9i

A simple sqlquery is created as following:
<sql-query name="SearchEmployees">
<return alias="e" class="com.gal.fast.common.hib.domain.SfaEmployees"/>
select e.* from employees e where e.last_name = ? order by e.last_name, e.first_name
</sql-query>

The statement
getCurrentSession().getNamedQuery(SearchEmployees).setParameter(0, "Test").scroll();
failed with java.sql.SQLException: ORA-01465: invalid hex number

But when change the statement to
getCurrentSession().getNamedQuery(SearchEmployees).setParameter(0, "Test", Hibernate.STRING).scroll();
it works fine.

Obviously the setParameter(int, object) could not guess the Hibernate type as it should from the object class.

Is this a configuration issue? Thank you advance for your reply.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 3:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
what type is last_name mapped as ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 3:17 pm 
Newbie

Joined: Mon Oct 16, 2006 10:36 am
Posts: 14
Location: Fort Worth, TX
varchar2(40 byte)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 3:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the hibernate type not the sql type.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 3:24 pm 
Newbie

Joined: Mon Oct 16, 2006 10:36 am
Posts: 14
Location: Fort Worth, TX
<property name="lastName" type="string">
<column name="LAST_NAME" length="40" not-null="true"/>
</property>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 3:28 pm 
Newbie

Joined: Mon Oct 16, 2006 10:36 am
Posts: 14
Location: Fort Worth, TX
But how is it related to the Hibernate type?

From the api doc, it says:"

public Query setParameter(int position,
Object val)
throws HibernateException

Bind a value to a JDBC-style query parameter, guessing the Hibernate type from the class of the given object." , it is assumed that the guessing is ONLY based on the Object type.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 3:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm the api doc is out of date.

With the new parser we are actually able to deduce what the expected type of the parameter is (in some cases) and uses that before falling back to heuristics based on the type of the object you pass in.

Would be interesting if you could step through the setParameter call and let me know what part of AbstractQueryImpl.determineType that actually gives the type ? (parameterMetadata.getOrdinalParameterExpectedType or guessType)

I'll go and update the javadocs now..

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 11:30 am 
Newbie

Joined: Mon Oct 16, 2006 10:36 am
Posts: 14
Location: Fort Worth, TX
Thank you for your assistance. I will go through the "guessing" and let you know what I find out.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 3:59 pm 
Newbie

Joined: Mon Oct 16, 2006 10:36 am
Posts: 14
Location: Fort Worth, TX
Have not gone to the Hibernate code. But found the determineType method is not fully implemented for native Oracle sql especially when the variables are in plsql functions such as decode


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 5:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
native oracle sql ?! that shouldn't affect our HQL query parsing...what are you referring to ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 10:28 am 
Newbie

Joined: Mon Oct 16, 2006 10:36 am
Posts: 14
Location: Fort Worth, TX
According the Hibernate doc, queries within sqlquery tag are consided to be native query, are they not?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 1:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ah ..didn't see your sqlquery in the initial question.

so again, what method is actually returning the guess type in your case ?

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 1:39 pm 
Newbie

Joined: Mon Oct 16, 2006 10:36 am
Posts: 14
Location: Fort Worth, TX
It looks like the determineType is used to guess the type for the setParameter(int, object) method in sqlquery.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 18, 2006 1:52 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
could you create a *minimal* test case that fails and put it in jira ?

i think this is an issue with the oracle drivers and not so much hibernate....but maybe we can detect that and avoid it. Would just be good with a failing testcase (remember to list db and jdbc driver version)

Thanks.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 10:11 am 
Newbie

Joined: Mon Oct 16, 2006 10:36 am
Posts: 14
Location: Fort Worth, TX
Hibernate obviously can not guess the parameter in this query:
SELECT DECODE('x', NULL, 'x', 'n') AS test_column FROM dual.

I am going to send the test case later.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 18 posts ]  Go to page 1, 2  Next

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.