通过休眠创建视图 [英] Creating views through hibernate
问题描述
在使用 hibernate.hbm2ddl.auto 属性创建表时,有什么方法可以创建视图.我正在使用注释类型来定义表及其字段.是否有任何属性也可用于通过休眠创建视图?
Is there any way to create a view when creating tables by using the hibernate.hbm2ddl.auto property. I am using annotation type for defining the table and its fields. Is there any property that I can use to create the view also through hibernate?
推荐答案
Hibernate 不会自动为您执行此操作.但是,以下解决方案之一可能对您有用:
Hibernate does not do that for you automatically. However, one of these solutions might be useful to you:
在您的数据库中创建一个视图,并使用休眠定义包含这些列的模型.如果 Hibernate 找到此视图,则不会为该模型创建表.其余的就像使用真正的桌子一样.
Create a view in your database, and define a model with those columns using hibernate. Hibernate does not create a table for that model, if it finds this view. And the rest is just like using a real table.
Hibernate 确实让您能够在 XML 映射文件中自己创建(和删除)其他数据库对象.像这样的东西.
Hibernate does give you the ability to create (and drop) additional database objects yourself in the XML mapping files. Something like this.
<database-object>
<create>create or replace view yourView</create>
<drop>drop view yourView</drop>
<dialect-scope name='org.hibernate.dialect.Oracle9Dialect' />
</database-object>
在我看来,第一种解决方案更容易处理,因为我目前正在使用这种方法来处理我的观点.
In my opinion the first solutions is way easier to handle, as I am currently using this method to treat my views.
这篇关于通过休眠创建视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!