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: Stored procedures and null parameters
PostPosted: Tue Feb 12, 2008 2:29 pm 
Newbie

Joined: Tue Feb 12, 2008 2:06 pm
Posts: 3
Hibernate version: NHibernate 1.2.0.4000

Hi,

I am having an issue with using SQL Server Stored Procedures with NHibernate:
I have a stored Proc P_SEARCH_EVENTS defined as such:
Code:
   @CountryCode as varchar(3) = null,
   @RegCode as varchar(50) = null,
   @StartDate as datetime = null,
   @EndDate as datetime = null


Each parameter can be either assigned, or being null (and then ignored by the search query).

I am mapping the stored Proc by putting
Code:
  <sql-query name="searchEvent">
    <return class="Event" />
    EXEC P_SEARCH_EVENTS ?, ?, ?, ?
  </sql-query>

In my mapping file.

The problem is that I cant figure how to call the function in my code (My DateTime are nullable, and then unusable by query.SetDateTime. I tried query.SetParameter but it raises an exception when the object is null (since it can't guess the type)

I also tried
Code:
            query.SetParameter(2, startDate, (NHibernate.Type.IType)typeof(DateTime?));

but no luck there either (not castable)

That's probably quite simple, but I couldn't figure it out with the documentation. Anyone got an idea?


Last edited by lucasbfr on Thu Feb 14, 2008 12:53 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 14, 2008 12:41 pm 
Newbie

Joined: Tue Feb 12, 2008 2:06 pm
Posts: 3
Bumping, no idea? :(


Top
 Profile  
 
 Post subject: Stored procedures and null parameters
PostPosted: Thu Feb 14, 2008 6:08 pm 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi,

I think the following would work:

Code:
.SetParameter(2, null, NHibernateUtil.DateTime)


Richard


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 15, 2008 6:12 am 
Newbie

Joined: Tue Feb 12, 2008 2:06 pm
Posts: 3
It does. Thanks a lot!


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.