-->
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: setParameter(i, null) fails with DB-specific exception
PostPosted: Mon Jul 10, 2006 10:24 am 
Newbie

Joined: Sat May 22, 2004 4:57 pm
Posts: 9
I noticed that AbstractQueryImpl.setParameter(i, object) falls back to the Serializable type immediately if the input parameter is null. This can cause DB-specific problems, such as "ERROR: operator does not exist: character varying = bytea" with PostgreSQL. (The untyped setParameter(i,obj) method is used heavily from Spring's HibernateTemplate class, which calls it from find(string query, obj param) methods.)

Since the parameter types in HQL are known a priori, though, it seems like AbstractQueryImpl could guess the object type based on context even if the value itself is null, and then fall back to Serializable later if no type can be guessed from context. (reference:
http://opensource.atlassian.com/project ... e/HHH-1129
)

Code:
public Query setParameter(int position, Object val) throws HibernateException {
// the offending lines
// if (val == null) {
//      setParameter( position, val, Hibernate.SERIALIZABLE );
//      }
//      else {
       setParameter( position, val, determineType( position, val ) );
//      }
    return this;
}


To verify this approach, I made a simple example ("from foo where bar = ?" with bar as a String) and took out the two lines in AbstractQueryImpl that fall back to Serializable. Then, StringType was correctly guessed even if the input is null.

Should I open this as a feature/enhancement request on JIRA?

Hibernate version: 3.1.3

Code between sessionFactory.openSession() and session.close():

Code:
Query q = session.createQuery("from foo where bar = ?");
q.setParameter(0, null);
return q.list();


Full stack trace of any exception that occurs:
PSQLException: ERROR: operator does not exist: character varying = bytea

Name and version of the database you are using: PostgreSQL 8.x

Debug level Hibernate log excerpt:
DEBUG AbstractBatcher [http-8088-Processor4] 10 Jul 2006 09:33:09: preparing statement DEBUG SerializableType [http-8088-Processor4] 10 Jul 2006 09:33:09: binding null to parameter: 1


Top
 Profile  
 
 Post subject: Re: setParameter(i, null) fails with DB-specific exception
PostPosted: Tue Oct 05, 2010 10:05 am 
Newbie

Joined: Tue May 18, 2010 5:39 am
Posts: 19
Duhh .. surprisingly this is never answered .. did you get a solution because now i face the same problem but with oracle.

_________________
AG
http://anshuiitk.blogspot.com


Top
 Profile  
 
 Post subject: Re: setParameter(i, null) fails with DB-specific exception
PostPosted: Thu Oct 07, 2010 3:57 am 
Beginner
Beginner

Joined: Fri Nov 14, 2008 7:34 pm
Posts: 24
you should use

"from foo where bar is null"


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.