title: In a Transactional function, calling clear() detach all entities?
body: <p>I am using Hibernate as JPA provider and in a function, I am creating an instance of different entities. Once I call <code>clear()</code> for one entity, I can't <code>persist()</code> the other entities. My code is pretty more complicated, and at a point I am obliged to call <code>flush()</code> and <code>clear()</code> for one type of entities (and NOT for the other types) in order to free some memory.</p>
  
  <p>A simplification of my code is as follow:</p>
  
  <pre><code>@Transactional
  void function()
  {
      EntityType1 entity1 = new  EntityType1();
      EntityType2 entity2 = new  EntityType2();
  
      //...... do operations on entity1
      entity1.persist();
      entity1.flush();
      entity1.clear();
  
      //...... do operations on entity2
      entity2.persist();
  }
  </code></pre>
  
  <p>When calling <code>entity2.persist()</code> I have the following error:
      org.springframework.orm.jpa.JpaSystemException: org.hibernate.PersistentObjectException: detached entity passed to persist</p>