<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>maonet technotes &#187; stored procedure</title>
	<atom:link href="http://maonet.wordpress.com/tag/stored-procedure/feed/" rel="self" type="application/rss+xml" />
	<link>http://maonet.wordpress.com</link>
	<description>IOC(SM):MOC(RM):TDD(NU):SCC(TFS):ORM(L2S):JSL(Jq):CIS(CC)</description>
	<lastBuildDate>Thu, 31 Dec 2009 17:16:53 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='maonet.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/27569a47b055d3d0ff1d52cf3b0ce0d7?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>maonet technotes &#187; stored procedure</title>
		<link>http://maonet.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://maonet.wordpress.com/osd.xml" title="maonet technotes" />
		<item>
		<title>NHibernate and Stored Procedure</title>
		<link>http://maonet.wordpress.com/2007/11/08/nhibernate-and-stored-procedure/</link>
		<comments>http://maonet.wordpress.com/2007/11/08/nhibernate-and-stored-procedure/#comments</comments>
		<pubDate>Thu, 08 Nov 2007 22:45:25 +0000</pubDate>
		<dc:creator>Frank Mao</dc:creator>
				<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[stored procedure]]></category>

		<guid isPermaLink="false">http://maonet.wordpress.com/2007/11/08/nhibernate-and-stored-procedure/</guid>
		<description><![CDATA[By creating 2 sets of properties in hbm mapping file, I finally made SP works in NH, kind of, delete SP still doesn&#8217;t work. I suspect it&#8217;s NH&#8217;s bug, because from the log I can tell the delete SP only be passed in one parameter which is the primary key column, while insert SP and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=41&subd=maonet&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>By creating 2 sets of properties in hbm mapping file, I finally made SP works in NH, kind of, delete SP still doesn&#8217;t work. I suspect it&#8217;s NH&#8217;s bug, because from the log I can tell the delete SP only be passed in one parameter which is the primary key column, while insert SP and update SP both can get all the parameters.</p>
<p>I also don&#8217;t like the idea of retrieve-first-then-delete. It&#8217;s real ORM, but sometimes we need a little bit exception to directly operate database. I noticed some NH members already working on this, in their internal <a href="http://jira.nhibernate.org/browse/NH-611">JIRA</a>. Hope I don&#8217;t need to wait too long to see this  <font color="#ff0000"><em>ISession.Delete&lt;T&gt;(Object id);</em></font></p>
<p>Some tick I&#8217;ve been used to make SP works in NH so far.</p>
<ol>
<li>Turn on sql debug.<br />
&lt;add key=&#8221;hibernate.show_sql&#8221; value=&#8221;true&#8221;/&gt;</li>
<li>Create a set of field column to save original values used by update SP.<br />
&lt;property name=&#8221;ColumnNameOriginal&#8221; column=&#8221;ColumnName&#8221; <font color="#ff0000">insert=&#8221;false&#8221;</font> access=&#8221;<font color="#0000ff">field</font>&#8220;/&gt;<br />
Insert SP doesn&#8217;t need this kind of property, so turn insert to off. By setting it&#8217;s access type to &#8216;field&#8217;, we don&#8217;t need to write getter/setter in domain object any more.</li>
<li>NHibernate.StaleStateException: Unexpected row count: -1; expected: 1<br />
SP needs to Set NoCount <font color="#ff0000">OFF.<br />
</font></p>
<blockquote><p>SET NOCOUNT &#8211; Stops the message indicating the number of rows affected by a Transact-SQL statement from being returned as part of the results.</p>
<p>But The stored procedures are in most cases (read: better do it than not) required to return the number of rows inserted/updated/deleted, as Hibernate has some runtime checks for the success of the statement. Hibernate always registers the first statement parameter as a numeric output parameter for the CUD operations:</p></blockquote>
</li>
<li>My custom sql:<br />
&lt;sql-insert&gt; EXECUTE Table_INS  ?,?,?,?,?,?,?,?,?,?,?,?   &lt;/sql-insert&gt;<br />
&lt;sql-update&gt; EXECUTE Table_UPD  ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?  &lt;/sql-update&gt;<br />
&lt;sql-delete&gt; EXECUTE Table_DEL  ?,?,?,?,?,?,?,?,?,?,?,?,?  &lt;/sql-delete&gt;<br />
I am mad at this unsorted parameter list. But what can I improve it? Using the pre-defined property name? How?</li>
<li>id column has to be set to <span class="term"><tt>increment,</tt></span> otherwise the insert SP won&#8217;t be triggered. I am using SQLServer 2005.</li>
<li>Output type parameter seems doesn&#8217;t work. Fortunately, primary key id can be catch successfully by real id column. For others, I think refresh/retrieve is the only option.</li>
</ol>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/maonet.wordpress.com/41/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/maonet.wordpress.com/41/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/maonet.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/maonet.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/maonet.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/maonet.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/maonet.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/maonet.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/maonet.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/maonet.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/maonet.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/maonet.wordpress.com/41/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=maonet.wordpress.com&blog=431779&post=41&subd=maonet&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://maonet.wordpress.com/2007/11/08/nhibernate-and-stored-procedure/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d41c3a25ca01f1e979e2bc86b8c4ed38?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">FMao</media:title>
		</media:content>
	</item>
	</channel>
</rss>