<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: SaveOrUpdate versus Merge in Hibernate</title>
	<atom:link href="http://www.stevideter.com/2008/12/07/saveorupdate-versus-merge-in-hibernate/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stevideter.com/2008/12/07/saveorupdate-versus-merge-in-hibernate/</link>
	<description>Technology, code, and thoughts by Stevi Deter</description>
	<lastBuildDate>Thu, 15 Dec 2011 15:20:14 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Sambath P</title>
		<link>http://www.stevideter.com/2008/12/07/saveorupdate-versus-merge-in-hibernate/comment-page-1/#comment-30063</link>
		<dc:creator>Sambath P</dc:creator>
		<pubDate>Sat, 19 Nov 2011 06:05:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.stevideter.com/?p=51#comment-30063</guid>
		<description>Thanks for the clear explanation of when to use merge.</description>
		<content:encoded><![CDATA[<p>Thanks for the clear explanation of when to use merge.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rishi</title>
		<link>http://www.stevideter.com/2008/12/07/saveorupdate-versus-merge-in-hibernate/comment-page-1/#comment-27426</link>
		<dc:creator>rishi</dc:creator>
		<pubDate>Wed, 28 Sep 2011 10:50:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.stevideter.com/?p=51#comment-27426</guid>
		<description>Nice post!

I have a question: Currently my app does not use Spring. It is using only Hibernate. I am facing this issue at multiple places and I am trying to make my middle layer and UI layer guys not to populate multiple objects with the same id in the first place. But to very little success.

Now we are thinking of bringing Spring layer over the hibernate (for many reasons). As spring handles the sessions by itself, do you think these exceptions will vanish and there no longer be attached and detached objects?</description>
		<content:encoded><![CDATA[<p>Nice post!</p>
<p>I have a question: Currently my app does not use Spring. It is using only Hibernate. I am facing this issue at multiple places and I am trying to make my middle layer and UI layer guys not to populate multiple objects with the same id in the first place. But to very little success.</p>
<p>Now we are thinking of bringing Spring layer over the hibernate (for many reasons). As spring handles the sessions by itself, do you think these exceptions will vanish and there no longer be attached and detached objects?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Varun</title>
		<link>http://www.stevideter.com/2008/12/07/saveorupdate-versus-merge-in-hibernate/comment-page-1/#comment-26845</link>
		<dc:creator>Varun</dc:creator>
		<pubDate>Tue, 13 Sep 2011 17:50:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.stevideter.com/?p=51#comment-26845</guid>
		<description>Thank you! :-)</description>
		<content:encoded><![CDATA[<p>Thank you! :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: thanh pham</title>
		<link>http://www.stevideter.com/2008/12/07/saveorupdate-versus-merge-in-hibernate/comment-page-1/#comment-26530</link>
		<dc:creator>thanh pham</dc:creator>
		<pubDate>Wed, 07 Sep 2011 16:00:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.stevideter.com/?p=51#comment-26530</guid>
		<description>Nice topic.

Thanks :)</description>
		<content:encoded><![CDATA[<p>Nice topic.</p>
<p>Thanks :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Willie</title>
		<link>http://www.stevideter.com/2008/12/07/saveorupdate-versus-merge-in-hibernate/comment-page-1/#comment-26081</link>
		<dc:creator>Willie</dc:creator>
		<pubDate>Tue, 30 Aug 2011 23:43:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.stevideter.com/?p=51#comment-26081</guid>
		<description>At the end you ask where we&#039;ve encountered the error. Exactly same place you mention--I have a graph and I&#039;m validating that there aren&#039;t any graph cycles.</description>
		<content:encoded><![CDATA[<p>At the end you ask where we&#8217;ve encountered the error. Exactly same place you mention&#8211;I have a graph and I&#8217;m validating that there aren&#8217;t any graph cycles.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: harshit</title>
		<link>http://www.stevideter.com/2008/12/07/saveorupdate-versus-merge-in-hibernate/comment-page-1/#comment-22953</link>
		<dc:creator>harshit</dc:creator>
		<pubDate>Thu, 23 Jun 2011 19:57:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.stevideter.com/?p=51#comment-22953</guid>
		<description>Good explaination bro..</description>
		<content:encoded><![CDATA[<p>Good explaination bro..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rakesh Kaki</title>
		<link>http://www.stevideter.com/2008/12/07/saveorupdate-versus-merge-in-hibernate/comment-page-1/#comment-22676</link>
		<dc:creator>Rakesh Kaki</dc:creator>
		<pubDate>Fri, 17 Jun 2011 09:23:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.stevideter.com/?p=51#comment-22676</guid>
		<description>That&#039;s really helped me. Thanks.</description>
		<content:encoded><![CDATA[<p>That&#8217;s really helped me. Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Revolução Java - Artigos, Tutoriais, Livros e Dicas atualizadas sobre o Mundo Java!</title>
		<link>http://www.stevideter.com/2008/12/07/saveorupdate-versus-merge-in-hibernate/comment-page-1/#comment-22384</link>
		<dc:creator>Revolução Java - Artigos, Tutoriais, Livros e Dicas atualizadas sobre o Mundo Java!</dc:creator>
		<pubDate>Fri, 10 Jun 2011 17:46:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.stevideter.com/?p=51#comment-22384</guid>
		<description>[...] Looking at that table one may begin to understand why the saveOrUpdate method never became a part of the JPA specification and why the JSR members instead choose to go with the merge method. BTW, you can find a different angle on the saveOrUpdate vs. merge problem in Stevi Deter’s blog about the subject. [...]</description>
		<content:encoded><![CDATA[<p>[...] Looking at that table one may begin to understand why the saveOrUpdate method never became a part of the JPA specification and why the JSR members instead choose to go with the merge method. BTW, you can find a different angle on the saveOrUpdate vs. merge problem in Stevi Deter’s blog about the subject. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dennis Moore</title>
		<link>http://www.stevideter.com/2008/12/07/saveorupdate-versus-merge-in-hibernate/comment-page-1/#comment-21294</link>
		<dc:creator>Dennis Moore</dc:creator>
		<pubDate>Sat, 14 May 2011 20:05:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.stevideter.com/?p=51#comment-21294</guid>
		<description>Thanks! Your code example is wonderful, very useful.</description>
		<content:encoded><![CDATA[<p>Thanks! Your code example is wonderful, very useful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shay</title>
		<link>http://www.stevideter.com/2008/12/07/saveorupdate-versus-merge-in-hibernate/comment-page-1/#comment-20980</link>
		<dc:creator>Shay</dc:creator>
		<pubDate>Tue, 03 May 2011 20:20:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.stevideter.com/?p=51#comment-20980</guid>
		<description>Stevi,

I have used your article to good effect at least once before and I&#039;m glad to see that when I search for &quot;hibernate merge versus save or update&quot;, it still comes up first. I&#039;m also happy to see that this advice is still helping people almost three years after you originally shared it with us. In return, I&#039;d like to share with you yet another reason for Hibernate throwing NonUniqueObjectException: loss of numeric precision.

Every morning, I download data from a feed and insert it into tables in a Sybase database using org.hibernate.Session.save(Object) [the table is truncated before the download begins]. One entity I insert contains many BigDecimal elements that are mapped to numeric(n, m) in its corresponding table. This has worked fine for over 18 months, until today, when a NonUniqueObjectException was thrown. I scratched my head for quite some time, knowing that the feed handler had not loaded this instance in memory until the point where the exception was being thrown. After a feeble attempt at debugging the feed handler, I decided to try inserting the offending instance directly into the table to see if that worked, and sure enough, it did, but with one small exception - the precision of one of the numeric columns was too small to hold the value I was giving it and Sybase silently truncated one decimal place at insertion. Modifying the entity to increase its precision and scale by several digits fixed my problem.

I am anything but a Hibernate maven (indomitable or spirited novice would be a more appropriate description) but it occurred to me that perhaps Hibernate is throwing a NonUniqueObjectException in this case because it is comparing the original object with the object returned by the database and finding that they are not the same. Would you agree?

Thanks again for this article,
Shay</description>
		<content:encoded><![CDATA[<p>Stevi,</p>
<p>I have used your article to good effect at least once before and I&#8217;m glad to see that when I search for &#8220;hibernate merge versus save or update&#8221;, it still comes up first. I&#8217;m also happy to see that this advice is still helping people almost three years after you originally shared it with us. In return, I&#8217;d like to share with you yet another reason for Hibernate throwing NonUniqueObjectException: loss of numeric precision.</p>
<p>Every morning, I download data from a feed and insert it into tables in a Sybase database using org.hibernate.Session.save(Object) [the table is truncated before the download begins]. One entity I insert contains many BigDecimal elements that are mapped to numeric(n, m) in its corresponding table. This has worked fine for over 18 months, until today, when a NonUniqueObjectException was thrown. I scratched my head for quite some time, knowing that the feed handler had not loaded this instance in memory until the point where the exception was being thrown. After a feeble attempt at debugging the feed handler, I decided to try inserting the offending instance directly into the table to see if that worked, and sure enough, it did, but with one small exception &#8211; the precision of one of the numeric columns was too small to hold the value I was giving it and Sybase silently truncated one decimal place at insertion. Modifying the entity to increase its precision and scale by several digits fixed my problem.</p>
<p>I am anything but a Hibernate maven (indomitable or spirited novice would be a more appropriate description) but it occurred to me that perhaps Hibernate is throwing a NonUniqueObjectException in this case because it is comparing the original object with the object returned by the database and finding that they are not the same. Would you agree?</p>
<p>Thanks again for this article,<br />
Shay</p>
]]></content:encoded>
	</item>
</channel>
</rss>

