title: Can I auto-detach SqlResultSetMapping Entity from EntityManager?
body: <p>I'm using a <code>@SqlResultSetMapping</code> for an <code>@Entity</code> that is purely read-only (and has no backing table in the database). I'm loading tens of thousands of these into memory, so I need to detach the entities from the EntityManager to avoid Hibernate's dirty entity checking when I do work later.</p>
  
  <p>Is there a way to annotate the Entity, or the SqlResultSetMapping, so that the entities are never added to the EntityManager?</p>
  
  <p>Non-persisted entity:</p>
  
  <pre><code>@SqlResultSetMapping(name = "fooMapping", entities = @EntityResult(entityClass = Foo.class))
  @Entity
  public class Foo {
      @Id
      public Long row_id;
      public String name;
  }
  </code></pre>
  
  <p>Native query:</p>
  
  <pre><code>String sql = "SELECT id AS row_id, friendlyName AS name FROM SomeTable"; 
  Query q = JPA.em().createNativeQuery(sql, "fooMapping");
  List&lt;Foo&gt; fooList = q.getResultList();
  </code></pre>
  
  <p>Current solution:</p>
  
  <pre><code>for (Foo f : fooList) {
      JPA.em().detach(f); // 100x improvement for subsequent DB work
  }
  
  // subsequent database work
  </code></pre>