-->
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.  [ 2 posts ] 
Author Message
 Post subject: AbstractQueryImpl.UniqueResult<T> executes the query t
PostPosted: Wed Dec 05, 2007 2:05 pm 
Newbie

Joined: Wed Dec 05, 2007 1:52 pm
Posts: 2
I have been using IQuery.UniqueResult<T> to execute a named query (stored procedure) that inserts rows into a table and returns the new row. Every execution it would mysteriously insert two new rows. I narrowed it down to the implementation of AbstractqueryImpl.UniqueResult<T>:

Code:
      public T UniqueResult<T>()
      {
         object result = UniqueResult();
         if (result == null && typeof(T).IsValueType)
         {
            throw new InvalidCastException("UniqueResult<T>() cannot cast null result to value type. Call UniqueResult<T?>() instead");
         }
         else
         {
            return (T)UniqueResult();
         }
      }


It first calls UniqueResult() to get a resulting value. After checking to see if the result is of the type requested it again calls UniqueResult() to return it's value. This was causing the query to be issued twice.

I'm not sure if this is an issue or if it is working as intended. It definitely caused me a headache. Perhaps I am using the wrong method to issue a stored procedure that inserts data?

Should this:

Code:
return (T)UniqueResult();


be changed to this:

Code:
return (T)result;


?

-Adam


Top
 Profile  
 
 Post subject: Nevermind...
PostPosted: Thu Dec 06, 2007 2:05 am 
Newbie

Joined: Wed Dec 05, 2007 1:52 pm
Posts: 2
Nevermind...

I found the link to the NHibernate issues page and see that the issue is slated as fixed.

http://jira.nhibernate.org/browse/NH-1170


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