2

I have a doubt regarding update or delete rows from a database view using Hibernate

I have the following in Entity

@Entity
@Table(name = "V_EMPLOYEES")
.....

V_EMPLOYEES is a database view used to join two tables

and in DAO class I am deleting a row by

entityManager.remove(entityManager.merge(employees));

Based on the above I could successfully delete a row based on Primary Key.

As I have mapped a view in Entity class, how does a row gets deleted from a table successfully? Because as per the Hibernate FAQ - view is just like any other table (except that you might not be able to update or insert to a view)

Any inputs or insights are highly appreciable.

My Hibernate version 4.1.0 Final

Jacob
  • 14,463
  • 65
  • 207
  • 320

1 Answers1

1

Oh, there is good question actually, For some kind of databases that you can insert even delete data from view such as Mysql. But the view should have some special feature, for example the view should include all the columns from 1 tables. Whether the operation can work or not depends on the database engine not hibernate.

OQJF
  • 1,350
  • 9
  • 12
  • I am using Oracle as database and as you have mentioned it is the database view does the trick, Hibernate is transparent. – Jacob Mar 20 '13 at 05:58
  • Yes, that's my mean. But I do don't know the logic of Oracle view, if you have idea, please tell me. Thanks. – OQJF Mar 20 '13 at 06:03
  • See [this](http://stackoverflow.com/questions/1652995/in-oracle-is-it-possible-to-insert-or-update-a-record-through-a-view), as my database view statisfies those conditions, Hibernate didn't complain whether it is table or view. And Oracle [doc](http://docs.oracle.com/cd/E17952_01/refman-5.1-en/view-updatability.html) – Jacob Mar 20 '13 at 06:07