Using views in JPA / Hibernate
843830Jun 23 2008 — edited Jun 24 2008Hello
I recently started to work with JPA and hibernate. I have this problem:
In my database, I have table named MyTable. In java source code, I have java class MyClass mapped to this table by JPA annotations @Entity(name="MyTable"). There are many tables in relation with this MyTable so I wrote a view V_MyTable to make it simple to work with it. This view has all MyTable columns, also another columns from joined tables and columns calculated with conditional expressions. Those joined and special columns are annotated not to include in insert and updates (@Column editable,insertable fields).
To keep it simple I would like to use this class mapping for selecting from table and also for inserting/updating/deleting. Is there any way to tell EntityManager that it should include "V_MyTable" (view name) in generated select but in other statements (for example update) "MyTable" (actual table name)?
Thank you for any advices.
Regards
jUmP3r