-->
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.  [ 4 posts ] 
Author Message
 Post subject: Oracle Error When Setting NULL Parameter Value
PostPosted: Wed Mar 12, 2008 9:00 am 
Newbie

Joined: Thu Mar 23, 2006 4:02 pm
Posts: 4
Hello,

I'm receiving an Oracle error when attempting to execute a native SQL query that uses a null parameter value. I've boiled it down to this test case:

Code:
final String SQL = "select username as userName from all_users where username = NVL(?, username)";
SQLQuery sqlQuery = getSession().createSQLQuery(SQL);
sqlQuery.setParameter(0, null);

List results = sqlQuery.list();


As you can see, the query uses Oracle's NVL function to handle null parameters.

However, when I run this code, it fails with an error on the sqlQuery.list() call. The error is as follows:

Code:
org.hibernate.exception.GenericJDBCException: could not execute query
...
...
Caused by: java.sql.SQLException: ORA-01465: invalid hex number


For some reason it doesn't like a null parameter, which should be valid and legal. If I use a string value for the parameter it works fine, but for some reason it doesn't like a null value.

I'm using Hibernate 3.2.6.ga and Oracle 10, along with ojdbc14.jar as the Oracle driver.

Any hints or suggestions? This is pretty critical for me as I'm trying to use it in a reporting framework.

Thank you!!!

-Ryan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 3:33 pm 
Newbie

Joined: Tue Nov 14, 2006 11:05 pm
Posts: 3
Location: Romania, Timisoara
I have the same config (hibernate 3.2.6 GA, Oracle 10g and ojdbc14.jar) and your code works with no problem. Maybe you're looking for the problem in the wrong place.

Could you please post the definition of the all_users table so I can perform a real test?

_________________
"When all think alike, then no one is thinking". Walter Lippman


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 3:55 pm 
Newbie

Joined: Tue Mar 11, 2008 6:41 pm
Posts: 8
Location: France
And what about:

Code:
sqlQuery.setParameter(0, null, org.hibernate.Hibernate.STRING);


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 13, 2008 10:15 am 
Newbie

Joined: Thu Mar 23, 2006 4:02 pm
Posts: 4
llefevre wrote:
And what about:

Code:
sqlQuery.setParameter(0, null, org.hibernate.Hibernate.STRING);


Yes, this works, as I eventually found out on my own. However, having to specify the Hibernate type could have been a real problem, because I wanted to use code similar to this in a reporting framework where the SQL isn't known, and thus the data type of the potential null value isn't known.

Fortunately, though, I have some back door ways of figuring out what the Hibernate type is, so I can specify the Hibernate type anyways.


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