title: JPA mapping views and tables with inheritance
body: <p>I have a db design that I cannot change. The db has tables and view which have a one to one relationship. The views hold some extra information that is calculated from the table. The relevant information being the status of the row. The permission set up for this relationship is views are read-only where as the tables have all CRUD operations available. JPA was the selected ORM to map to this setup. The app is a basic CRUD app with some validation by checking statuses and other attributes in the view then inserting/updating the corresponding tables. Here is an example of two approaces I have tried to model this case. I was wondering which one is more efficient, easier to work with, and/or the 'correct way' to do this.</p>
  
  <p>Option 1 - This options is nice because I can use all the JPA provided interfaces to interact with the DB. This options is bad because I have to sometimes load a table and a model which seems very redundant and I have 3 files per table.</p>
  
  <pre><code>    Model.java
      package models;
      // relevant imports
      public abstract class Model {
         // columns that are shared with table and view
      }
  
      Table.java
      package models;
      // relevant imports
      @entity("table")
      public class Table extends Model {
         // Relationships with other tables 
      }
  
      View.java
      package models;
      // relevant imports
      @entity("view")
      public class View extends Model {
         // View specific columns ...
         // Relationships with other views
      }
  </code></pre>
  
  <p>Option 2 - This option is nice because I only ever have to load the view and I have one file per table. This option is bad because for the CUD operations I have to write native SQL.</p>
  
  <pre><code>    Model.java
      package models;
      // relevant imports
      @entity("view")
      public class Model {
         // All VIEW + table columns
         // All relationships with other models
         // custom SQL to insert update or delete
      }
  </code></pre>