adding primary key to sql view

后端 未结 1 1801
萌比男神i
萌比男神i 2020-12-01 13:23

Reading that

how to do hibernate mapping for table or view without a primary key

I am wondering how to add a primary key to my view as it is

相关标签:
1条回答
  • 2020-12-01 13:48

    We can add a disabled primary key constraint to a view. That is, the constraint does not fire if an insert or update is run against the view. The database expects integrity to be maintained through constraints on the underlying tables. So the constraint exists solely for the purposes of documentation.

    SQL> create view emp_view as select * from emp
      2  /
    
    
    View created.
    
    SQL> alter view emp_view add constraint vemp_pk primary key (empno) disable
      2  /
    
    View altered.
    
    SQL> 
    

    Caveat: I have never tried this with Hibernate, so I don't know whether it would work in your scenario. However, I do know sites which use Hibernate exclusively against a layer of views, so I presume it does. Please experiment with the syntax and report back.

    0 讨论(0)
提交回复
热议问题