<?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/"
	>

<channel>
	<title>simonpena.com &#187; deleted entity passed to persist</title>
	<atom:link href="http://simonpena.com/blog/tag/deleted-entity-passed-to-persist/feed/" rel="self" type="application/rss+xml" />
	<link>http://simonpena.com/blog</link>
	<description>Una mezcla heterogénea de tecnología y desvaríos</description>
	<lastBuildDate>Tue, 11 Oct 2011 19:14:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Hibernate common errors</title>
		<link>http://simonpena.com/blog/proyectos/pennybank/hibernate-common-errors/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hibernate-common-errors</link>
		<comments>http://simonpena.com/blog/proyectos/pennybank/hibernate-common-errors/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 22:43:26 +0000</pubDate>
		<dc:creator>Simón</dc:creator>
				<category><![CDATA[Pennybank]]></category>
		<category><![CDATA[deleted entity passed to persist]]></category>
		<category><![CDATA[detached entity passed to persist]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[id to load is required for loading]]></category>

		<guid isPermaLink="false">http://pennybank.wordpress.com/?p=43</guid>
		<description><![CDATA[A better explanation about some usual Hibernate-related errors: deleted entity passed to persist, detached entity passed to persist and id to load is required for loading<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/hibernate-common-errors/' addthis:title='Hibernate common errors '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Just two days after I <a title="Mind the Cascade" href="http://www.simonpena.com/blog/proyectos/pennybank/mind-the-cascade" target="_blank">blogged</a> <a title="Testing..." href="http://www.simonpena.com/blog/proyectos/pennybank/testing" target="_blank">about</a> the errors <strong>deleted entity passed to persist</strong>, <strong>detached entity passed to persist</strong> and <strong>id to load is required for loading</strong>, some people came here from web searches.</p>
<p>As I'm not sure if those explanations were clear enough, I'll try to synthesise here:</p>
<ul>
<li><strong>Deleted entity passed to persist</strong>. One entity, supposed to be deleted, is still referenced / accessed. In my case, I had a problem with "<em>cascading</em>". The behavior I expected was "<strong>on delete cascade</strong>" and "<strong>on update cascade</strong>". I have those constraints well in the database, but they weren't right in the Hibernate annotations. After I changed that, the error stopped. While I was searching why I was getting this error, I've seen people whose problem was different. They had, let's say, a list of entities. Those entities were related to others, and, when deleting, they had to take care of deleting both the link and the persisted entity. This was the most common scenario of this problem, and is better explained <a title="Ejb3 Tutorial 3 - Finish Conversion" href="http://schuchert.wikispaces.com/Ejb3+Tutorial+3+-+Finish+Conversion" target="_blank">here</a>, for example.</li>
<li><strong>Detached entity passed to persist</strong>. One entity, which is supposed to be up to date but is not, is passed to persist. In my case, I was trying to create an entity (an Operation), related to another (the Account where that Operation was taking place). The persist action was failing because my version of the Account was incorrect. The solution was just to update the entity.</li>
<li><strong>Id to load is required for loading</strong>. Trying to access an entity without giving an actual identifier. In my case this was the easiest problem: I was calling <em>find</em> passing a non initialized long. Passing the correct, initialized values fixed the problem.</li>
</ul>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/hibernate-common-errors/' addthis:title='Hibernate common errors '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://simonpena.com/blog/proyectos/pennybank/hibernate-common-errors/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mind the Cascade</title>
		<link>http://simonpena.com/blog/proyectos/pennybank/mind-the-cascade/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mind-the-cascade</link>
		<comments>http://simonpena.com/blog/proyectos/pennybank/mind-the-cascade/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 03:33:00 +0000</pubDate>
		<dc:creator>Simón</dc:creator>
				<category><![CDATA[Pennybank]]></category>
		<category><![CDATA[CascadeType]]></category>
		<category><![CDATA[deleted entity passed to persist]]></category>
		<category><![CDATA[detached entity passed to persist]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[JUnit]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://pennybank.wordpress.com/?p=28</guid>
		<description><![CDATA[Refactoring JUnit tests and changing the way account operations are organized has revealed some bad annotations.<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/mind-the-cascade/' addthis:title='Mind the Cascade '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Today I decided to go through the model layer, implementing as many <a title="JUnit.org" href="http://www.junit.org/" target="_blank">JUnit</a> tests as I could, and completing all the actions I hadn't implemented yet. As I said <a title="Classifying account operations" href="http://www.simonpena.com/blog/proyectos/pennybank/classifying-account-operations" target="_blank">before</a>, I had just decided to stick to <em>one-category-at-a-time </em>scheme, having a hierarchical relationship between categories.</p>
<p>I thought it would be easy: change the Category entity, check the <em>on delete </em>and <em>on update </em>constraints in the database creation script, refactor and go on.I also had in mind some refactor in my JUnit tests: I have just two cases, one for each Facade, and several methods inside, for each of the actions in that facade. But as the application was getting larger and larger, I decided to have one JUnit case for each Facade Method, with several test methods for each of the possible scenarios I can think of.</p>
<p>So I was there, refactoring tests, moving some code to the <a title="@BeforeClass annotation" href="http://junit.org/apidocs/org/junit/BeforeClass.html" target="_blank"><em>setUpBeforeClass</em></a> and <a title="@AfterClass annotation" href="http://junit.org/apidocs/org/junit/AfterClass.html" target="_blank"><em>tearDownAfterClass</em></a> methods, when everything started to break:</p>
<p><strong>deleted entity passed to persist</strong> and <strong>detached entity passed to persist</strong>. After some research in Google, I understood what could be causing the second error, so I solved it:</p>
<p>I was using an entity in a call to persist which had been "left" unchecked by the entity manager  (detached is the word, but I didn't know it). I got the entity again by invoking <em>find</em>, and passed it fresh, and it worked out.</p>
<p>But the first problem was harder. Google didn't shed any light on me (apparently), as everything was about deleted entities which were still referenced by others related to them. I didn't have any entity left: this was happening in the <em>tearDownAfterClass</em> method, and I was removing the entities left after the test. And then I realized that most of the clean up was supposed to be done by cascading. So, maybe <a title="CascadeType (JAVA EE 5)" href="http://java.sun.com/javaee/5/docs/api/javax/persistence/CascadeType.html" target="_blank">cascading</a> tags were incorrect. I checked out my classes, and I changed some of them: putting the explicit ones instead of <strong>CascadeType.ALL</strong>. I still have to test some of the <em>Update</em> methods, but for today, it's fixed.</p>
<div class="addthis_toolbox addthis_default_style " addthis:url='http://simonpena.com/blog/proyectos/pennybank/mind-the-cascade/' addthis:title='Mind the Cascade '  ><a class="addthis_button_facebook_like" fb:like:layout="button_count"></a><a class="addthis_button_tweet"></a><a class="addthis_button_google_plusone" g:plusone:size="medium"></a><a class="addthis_counter addthis_pill_style"></a></div>]]></content:encoded>
			<wfw:commentRss>http://simonpena.com/blog/proyectos/pennybank/mind-the-cascade/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

