<?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: Soft deletes using Hibernate annotations.</title>
	<atom:link href="http://featurenotbug.com/2009/07/soft-deletes-using-hibernate-annotations/feed/" rel="self" type="application/rss+xml" />
	<link>http://featurenotbug.com/2009/07/soft-deletes-using-hibernate-annotations/</link>
	<description>It's all just a matter of perspective.</description>
	<lastBuildDate>Mon, 09 Jan 2012 14:59:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Brian</title>
		<link>http://featurenotbug.com/2009/07/soft-deletes-using-hibernate-annotations/comment-page-1/#comment-190</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Mon, 09 Jan 2012 14:59:43 +0000</pubDate>
		<guid isPermaLink="false">http://featurenotbug.com/?p=89#comment-190</guid>
		<description>Ustun - You should be able to set the field to 0 in the Constructor.</description>
		<content:encoded><![CDATA[<p>Ustun &#8211; You should be able to set the field to 0 in the Constructor.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://featurenotbug.com/2009/07/soft-deletes-using-hibernate-annotations/comment-page-1/#comment-189</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Mon, 09 Jan 2012 14:58:20 +0000</pubDate>
		<guid isPermaLink="false">http://featurenotbug.com/?p=89#comment-189</guid>
		<description>Thanks for sharing Flemming.</description>
		<content:encoded><![CDATA[<p>Thanks for sharing Flemming.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Flemming Behrend</title>
		<link>http://featurenotbug.com/2009/07/soft-deletes-using-hibernate-annotations/comment-page-1/#comment-188</link>
		<dc:creator>Flemming Behrend</dc:creator>
		<pubDate>Fri, 30 Dec 2011 08:47:48 +0000</pubDate>
		<guid isPermaLink="false">http://featurenotbug.com/?p=89#comment-188</guid>
		<description>property name=&quot;hibernate.ejb.interceptor&quot; value=&quot;dk.topdanmark.td.core.persistence.SoftDeleteInterceptor&quot;</description>
		<content:encoded><![CDATA[<p>property name=&#8221;hibernate.ejb.interceptor&#8221; value=&#8221;dk.topdanmark.td.core.persistence.SoftDeleteInterceptor&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Flemming Behrend</title>
		<link>http://featurenotbug.com/2009/07/soft-deletes-using-hibernate-annotations/comment-page-1/#comment-187</link>
		<dc:creator>Flemming Behrend</dc:creator>
		<pubDate>Fri, 30 Dec 2011 08:46:12 +0000</pubDate>
		<guid isPermaLink="false">http://featurenotbug.com/?p=89#comment-187</guid>
		<description>Hi

Another way to implement soft delete is with an interceptor.

I tried this method first but got into trouble when having catalog prefix before my table name.

What I did instead was to implement a SoftDeleteInterceptor that intercepted the prepared stmt and modified it to an update stmt.

This will of course make it impossible to delete anything, but if that is the preferred behaviour it will work.


public class SoftDeleteInterceptor extends EmptyInterceptor {

	private static final long serialVersionUID = 1L;

	@Override
	public String onPrepareStatement(String sql) {
		System.err.println(sql);
		if (sql.startsWith(&quot;delete from&quot;)) {
			String softDeleteSql = sql.replace(&quot;delete from&quot;, &quot;update&quot;).replace(&quot;where&quot;, &quot;set c_rcd_del = &#039;Y&#039; where&quot;);
			return super.onPrepareStatement(softDeleteSql);
		}
		return super.onPrepareStatement(sql);
	}

}

To activate the interceptor add the following to persistence.xml


</description>
		<content:encoded><![CDATA[<p>Hi</p>
<p>Another way to implement soft delete is with an interceptor.</p>
<p>I tried this method first but got into trouble when having catalog prefix before my table name.</p>
<p>What I did instead was to implement a SoftDeleteInterceptor that intercepted the prepared stmt and modified it to an update stmt.</p>
<p>This will of course make it impossible to delete anything, but if that is the preferred behaviour it will work.</p>
<p>public class SoftDeleteInterceptor extends EmptyInterceptor {</p>
<p>	private static final long serialVersionUID = 1L;</p>
<p>	@Override<br />
	public String onPrepareStatement(String sql) {<br />
		System.err.println(sql);<br />
		if (sql.startsWith(&#8220;delete from&#8221;)) {<br />
			String softDeleteSql = sql.replace(&#8220;delete from&#8221;, &#8220;update&#8221;).replace(&#8220;where&#8221;, &#8220;set c_rcd_del = &#8216;Y&#8217; where&#8221;);<br />
			return super.onPrepareStatement(softDeleteSql);<br />
		}<br />
		return super.onPrepareStatement(sql);<br />
	}</p>
<p>}</p>
<p>To activate the interceptor add the following to persistence.xml</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ustun</title>
		<link>http://featurenotbug.com/2009/07/soft-deletes-using-hibernate-annotations/comment-page-1/#comment-179</link>
		<dc:creator>Ustun</dc:creator>
		<pubDate>Wed, 23 Nov 2011 08:04:01 +0000</pubDate>
		<guid isPermaLink="false">http://featurenotbug.com/?p=89#comment-179</guid>
		<description>Thanks, I got it working after setting the delete field to 0 manually. Do you know of a way to set the newly added `delete&#039; field to 0? Simply putting private char delete = 0 or &#039;0&#039; did not put in the new fields. (I used the following: update media set deleted=0 where deleted is null; ) do you know of a simpler way?</description>
		<content:encoded><![CDATA[<p>Thanks, I got it working after setting the delete field to 0 manually. Do you know of a way to set the newly added `delete&#8217; field to 0? Simply putting private char delete = 0 or &#8216;0&#8242; did not put in the new fields. (I used the following: update media set deleted=0 where deleted is null; ) do you know of a simpler way?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://featurenotbug.com/2009/07/soft-deletes-using-hibernate-annotations/comment-page-1/#comment-174</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Sat, 19 Nov 2011 13:09:26 +0000</pubDate>
		<guid isPermaLink="false">http://featurenotbug.com/?p=89#comment-174</guid>
		<description>You are welcome James. Glad it helped.</description>
		<content:encoded><![CDATA[<p>You are welcome James. Glad it helped.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James</title>
		<link>http://featurenotbug.com/2009/07/soft-deletes-using-hibernate-annotations/comment-page-1/#comment-173</link>
		<dc:creator>James</dc:creator>
		<pubDate>Sat, 19 Nov 2011 01:42:10 +0000</pubDate>
		<guid isPermaLink="false">http://featurenotbug.com/?p=89#comment-173</guid>
		<description>Thank you, Brian. You&#039;ve saved my life. I was banging my head against the wall to make soft-delete work. Thanks!!!!</description>
		<content:encoded><![CDATA[<p>Thank you, Brian. You&#8217;ve saved my life. I was banging my head against the wall to make soft-delete work. Thanks!!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John B.</title>
		<link>http://featurenotbug.com/2009/07/soft-deletes-using-hibernate-annotations/comment-page-1/#comment-168</link>
		<dc:creator>John B.</dc:creator>
		<pubDate>Tue, 15 Nov 2011 18:53:00 +0000</pubDate>
		<guid isPermaLink="false">http://featurenotbug.com/?p=89#comment-168</guid>
		<description>Sorry, I guess my question is the exact same as Mohammad&#039;s</description>
		<content:encoded><![CDATA[<p>Sorry, I guess my question is the exact same as Mohammad&#8217;s</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John B.</title>
		<link>http://featurenotbug.com/2009/07/soft-deletes-using-hibernate-annotations/comment-page-1/#comment-167</link>
		<dc:creator>John B.</dc:creator>
		<pubDate>Tue, 15 Nov 2011 18:39:31 +0000</pubDate>
		<guid isPermaLink="false">http://featurenotbug.com/?p=89#comment-167</guid>
		<description>Hi, 

Great post! Thanks for the information.

I was wondering if there is anyway to use the @SQLDelete in a generic way so that I could use it in a mapped superclass?

I have a base entity that I want to use for all my entities, and I need the soft delete for each as well. I was hoping there was a way to setup the query so that it updates the correct table.

Thanks,
John</description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>Great post! Thanks for the information.</p>
<p>I was wondering if there is anyway to use the @SQLDelete in a generic way so that I could use it in a mapped superclass?</p>
<p>I have a base entity that I want to use for all my entities, and I need the soft delete for each as well. I was hoping there was a way to setup the query so that it updates the correct table.</p>
<p>Thanks,<br />
John</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian</title>
		<link>http://featurenotbug.com/2009/07/soft-deletes-using-hibernate-annotations/comment-page-1/#comment-160</link>
		<dc:creator>Brian</dc:creator>
		<pubDate>Fri, 05 Aug 2011 14:21:31 +0000</pubDate>
		<guid isPermaLink="false">http://featurenotbug.com/?p=89#comment-160</guid>
		<description>Selman - I am assuming you have both &#039;hidden&#039; and &#039;id&#039; fields in your domain class file?</description>
		<content:encoded><![CDATA[<p>Selman &#8211; I am assuming you have both &#8216;hidden&#8217; and &#8216;id&#8217; fields in your domain class file?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

