将主键添加到 sql 视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2041308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
adding primary key to sql view
提问by Hoax
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 viewas it is basically just a stored query...?
我想知道如何将主键添加到我的视图中,因为它基本上只是一个存储查询......?
PS: oracle 10g
PS:甲骨文10g
thx
谢谢
回答by APC
We can add a disabledprimary 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.
警告:我从未在 Hibernate 中尝试过这个,所以我不知道它是否适用于您的场景。但是,我确实知道专门针对视图层使用 Hibernate 的站点,所以我认为它确实如此。请尝试语法并报告。