title: JPA and Table Views. Can it be done?
body: <p>We currently have a Java EE system where we are mapping to our database using JPA. It is a fairly well developed system with about 20 entities.</p>
  
  <p>We now have been ordered to use Views for everything. Eg: if we have a table called <strong>PERMISSION</strong> then we also need a view called <strong>PERMISSION_VIEW</strong>. Basically we need to do this to every table, and our applications can only access the data by querying the view.</p>
  
  <p>Now all our entity beans look like this :</p>
  
  <pre><code>@Entity
  @Table(name = "PERMISSION")
  @NamedQueries({
          @NamedQuery(name = "Permission.findByPK", query = "SELECT p FROM Permission p WHERE p.dpNum = :dpNumber"),
          @NamedQuery(name = "Permission.deleteAll", query = "DELETE FROM Permission") })
  public class Permission implements Serializable {
  
  }
  </code></pre>
  
  <ul>
  <li>Firstly, how is it possible to update tables if you are only allowed to use Views. Can Materialised Views work for this?</li>
  <li>Secondly, how much rewriting is going to be needed, if we can only use Views? Eg. For each entiry we will need to write <strong>@Table(name = "PERMISSION_VIEW")</strong>, to describe the entity, BUT, when doing an update it needs to do that to the PERMISSION table. How on earth do you consolidate this in an entity bean?</li>
  </ul>