-->
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: How can I pass a NULL search criteria to sql query?
PostPosted: Fri Jun 29, 2007 6:55 am 
Newbie

Joined: Mon May 14, 2007 2:07 pm
Posts: 5
Hello
I can't figure out how to pass a null through hibernate to a sql query as a search parameter. The query uses the COALESCE function to dynamically build my query search criteria:
In straing SQL:
Code:
      
SELECT u.USERNAME AS USERNAME , u.ID USER_ID, h.* FROM TFL_ATU_CONTACT contact
              left join TFL_ATU_TOPUP_HISTORY h ON contact.ATU_TOPUP_HISTORY_ID = h.ID
               left join TFL_CARD card ON h.PRESTIGE_ID=card.PRESTIGE_ID
             left join TFL_USER_TO_CARD u2card ON u2card.PRESTIGE_ID=card.PRESTIGE_ID
              left join TFL_USER u ON u.ID = u2card.USER_ID
         GROUP BY 
      h.ID,
      h.PRESTIGE_ID,
      h.STATUS,
      h.PICKUP_DATE,
      h.PICKUP_STATION_NLC,
      h.ATU_STATE_ID,
      h.AMOUNT,
      h.BUS_ROUTE,
      h.LAST_MODIFIED,
      h.CREATE_DATE,
      u.ID,
      u.USERNAME
      HAVING u.USERNAME= COALESCE(NULL, u.USERNAME)
                             h.PICKUP_DATE= COALESCE(NULL, h.PICKUP_DATE)


I want to alter this to take a parameter passed by code ie
code]
HAVING u.USERNAME= COALESCE(?, u.USERNAME)
h.PICKUP_DATE= COALESCE(?, h.PICKUP_DATE)
[/code]

So I can execute:

Code:
.findByNamedQuery("my.query.name", new Object[] {null});


When I run this I get the following error
Code:
2007-06-29 11:55:07,627 DEBUG [org.hibernate.type.SerializableType] - <binding null to parameter: 1>
2007-06-29 11:55:07,674 WARN [org.hibernate.util.JDBCExceptionReporter] - <SQL Error: 932, SQLState: 42000>
2007-06-29 11:55:07,674 ERROR [org.hibernate.util.JDBCExceptionReporter] - <ORA-00932: inconsistent datatypes: expected BINARY got CHAR>



I'm pretty stuck with this so any help would be great

Many thanks in advance
BM
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 11:28 am 
Newbie

Joined: Mon May 14, 2007 2:07 pm
Posts: 5
Might be worth mentioning that I am trying to build a dynamically generated query and my existing entity model doesn't really support HQL/Criteria usage for this purpose.
I want to to know how I can achieve the following:

Code:
PreparedStatement.setNull(int paramIndex,
             int sqlType,
             String typeName)



Kind regards for any advise you can offer.

BM


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 22, 2007 10:18 pm 
Newbie

Joined: Mon Jan 01, 2007 9:43 pm
Posts: 11
Its my understanding that you cannot bind a NULL to a query parameter


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.