title: Removing an entity, but using the same primary key to add a similar entity after the removal
body: <p>Im trying to remove an entity which has a unique PK like : 80253</p>
  
  <p>I remove this entity by doing the follow lines of code: </p>
  
  <pre><code>myEntityType1 = getEntityManager().find(MyEntityType1.class, 80253);
  getEntityManager().remove(myEntityType1);
  getEntityManager().flush();
  </code></pre>
  
  <p>These bits of code actually deletes the rows from my database and all its cascading objects properly, and Im very happy about this. Now the problem occurs when I now need to create a similar entity that uses the same primary key (which should now be gone right?).</p>
  
  <pre><code>MyEntityType2 myEntityType2 = new MyEntityType2 ();
  myEntityType2.copyData(myEntityType1); //access the data from the other object
  //and retrieves the id 80253. myEntityType2 now has 80253 as ID.
  getEntitymanager().persist(myEntityType2);
  </code></pre>
  
  <p>Now this is where I get a unique constraint SQL error. Im trying to insert a ID which already exists and the changes are automatically rolled back (the old entity is no longer deleted). This happens after I see in my logger that toplink has deleted the records of the old entity. </p>
  
  <p>Does anyone know how this happens, and why its not working? For the record Ive tried merging, closing, clearing of the entityManager, but nothing seems to work.</p>
  
  <p>It seems to me that JPA might do some bad caching or something. I hope someone has a good answer for me! =)</p>
  
  <p><strong>Update:</strong> Theres no longer an issue with unique ID constraints, but I create a new subclass with the same primary key which has been deleted I get the following exception: </p>
  
  <pre><code>Exception Description: Trying to invoke [setApprovedWhen] on the object [null].  The 
  number of actual and formal parameters differs, or an unwrapping conversion has failed.
  Internal Exception: java.lang.IllegalArgumentException: object is not an instance of 
  declaring class
  </code></pre>
  
  <p>It seems to me that it wont let me change the object into a different subclass?</p>