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.
We now have been ordered to use Views for everything. Eg: if we have a table called PERMISSION then we also need a view called PERMISSION_VIEW. Basically we need to do this to every table, and our applications can only access the data by querying the view.
Now all our entity beans look like this :
@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 {
}
For more info on JPA and database views see, http://en.wikibooks.org/wiki/Java_Persistence/Advanced_Topics#Views
In JPA you can map to a
VIEW
the same as a table, using the @Table annotation. You can then map each column in the view to your object's attributes. Views are normally read-only, so object's mapping to views are normally also read-only. In most databases views can also be updatable depending on how complex to query is that they encapsulate. Even for complex queries database triggers can normally be used to update into the view.