title: Load Entity from View in JPA/Hibernate
body: <p>I have an application which uses Spring and Hibernate. In my database there are some views that I need to load in some entities. So I'm trying to execute a native query and load the class withthe data retrieved from the view:</p>
  
  <pre><code>//In my DAO class (@Repository) 
  public List&lt;MyClass&gt; findMyEntities(){
      Query query = em.createNativeQuery("SELECT * FROM V_myView", MyClass.class);
      return query.getResultList();
  }
  </code></pre>
  
  <p>and MyClass has the same fields as the column names of the view.</p>
  
  <p>The problem is that Hibernate can't recognize MyClass because it's not an entity (it's not annotated with @Entity)</p>
  
  <blockquote>
    <p>org.hibernate.MappingException: Unknown entity</p>
  </blockquote>
  
  <p>If I put MyClass as an entity the system will put try to create/update a table for that entity, because I have configured it :</p>
  
  <blockquote>
    <p><code>&lt;property name="hibernate.hbm2ddl.auto" value="update"/&gt;</code></p>
  </blockquote>
  
  <p>So I come into these questions:</p>
  
  <ol>
  <li>Can I disable "hibernate.hbm2ddl.auto" just for a single entity?</li>
  <li>Is there any way to load the data from a view into a non-entity class?</li>
  <li>If not, what would be the best way in my case for loading the data from a view into a class in hibernate?</li>
  </ol>
  
  <p>Thanks</p>