
If you like this post, check out my book Hibernate Tips: More than 70 solutions to common Hibernate problems. List bvs = em.createQuery("SELECT v FROM BookView v", BookView.class).getResultList() The tells Hibernate to ignore all changes on this entity, but you can use it in your queries to read data from your database.

You can easily achieve this with the Hibernate-specific which I use in the following code snippet. You should therefore also prevent Hibernate from updating it. You just have to define an entity that maps the view with the specific name and one or more of its columns.īut the normal table mapping is not read-only, and you can use the entity to change its content.ĭepending on the database you use and the definition of the view, you’re not allowed to perform an update on the view content. How can I map a read-only database view with Hibernate? Solution:ĭatabase views, in general, are mapped in the same way as database tables. Get more videos in the Hibernate Tips playlist Question:

If you have a question for a future Hibernate Tip, please leave a comment below. Some of the most popular tips are also available as a book.

Hibernate Tips is a series of posts in which I describe a quick and easy solution for common Hibernate questions. JBoss Tools is an umbrella project for a set of Eclipse plugins that includes support for JBoss and related technologies, such as Hibernate, JBoss AS / WildFly, CDI, OpenShift, Apache Camel, Red Hat JBoss Fuse, Docker, JSF, (X)HTML, Maven, and more.
