title: How to map two JPA or Hibernate entities on the same database table
body: <p>In our project, we have an entity 'Restaurant' with nearly 30 fields(some have relationships with other entities). So, every time we need a 'Restaurant' object even for a few fields, all the others are retrieved. This effects the performance. So, in the HBM file, we wrote two classes both pointing to the same physical class and same database table, as shown below.</p>
  
  <pre><code>=== restaurant.hbm.xml ===
  &lt;!-- Light Weight Version --&gt;
  &lt;class name="com.raj.model.Restaurant" table="RESTAURANTS" entity-name="RestaurantLite" 
                  dynamic-update="false" dynamic-insert="false"&gt;
  &lt;cache usage="read-only"/&gt;
       &lt;!-- few basic properties and relationships --&gt;
  &lt;/class&gt;
  
  &lt;!-- Restaurant --&gt;
  &lt;class name="com.raj.model.Restaurant" table="RESTAURANTS" entity-name="Restaurant"&gt;
       &lt;!-- all properties and relationships --&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p>In one of the DAO implementations, we are using Criteria which takes 'RestaurantLite' and returning list of restaurants as shown below.</p>
  
  <pre><code>Criteria criteria = session.createCriteria("RestaurantLite");
  
     // criteria related stuff
  
  return new LinkedHashSet&lt;Restaurant&gt;(criteria.list());
  </code></pre>
  
  <p>Now we want to remove all hbm files and use annotations. So how the same can be done using annotations for entites? Do we need to create an extra class 'RestaurantLite'? If then, how the above criteria returns 'Restaurant' objects??</p>