简体   繁体   English

如何从grails的databace视图创建域

[英]how to create domain from databace view from grails

I tried to create domain class from database view. 我试图从数据库视图创建域类。 But when I try run project I see: 但是当我尝试运行项目时,我看到:

Error | 错误 2016-01-19 17:15:00,525 [Thread-11] ERROR spi.SqlExceptionHelper - ORA- 01702: a view is not appropriate here Error | 2016-01-19 17:15:00,525 [Thread-11]错误spi.SqlExceptionHelper-ORA-01702:视图在此处不合适 2016-01-19 17:15:00,526 [Thread-11] ERROR hbm2ddl.SchemaUpdate - HHH000299: Could not complete schema update 2016-01-19 17:15:00,526 [Thread-11]错误hbm2ddl.SchemaUpdate-HHH000299:无法完成架构更新

my class: 我的课:

class Branch {

int id
String name

    static mapping = {
        table 'smart_branch'
        version false
        cache: 'read-only'
        id column: 'id'
        name column: 'name'
    }

    static constraints = {
    }
}

I use oracle 10g and in the view I use link to another oracle database. 我使用oracle 10g,并在视图中使用到另一个oracle数据库的链接。

view: 视图:

create or replace view branch (id, name) as (select id, convert(zzz.convert2@b(name)) from zzz.branch@db emp)

Domain class is an entity, a table inside db on which you can run DML queries. 域类是一个实体,是db内部的一个表,可以在其上运行DML查询。 Views are mainly used for only fetching the data and not modifying it. 视图主要用于仅获取数据而不修改数据。

You should also not try that. 您也不应尝试这样做。 Also if you are using Hibernate to generate schema for you, then you can't have a table and a view with same name. 同样,如果您正在使用Hibernate为您生成模式,那么您将无法使用同名的表和视图。 You would have to either set dbCreate mode to none in your DataSource.groovy or remove the mapping of the doamin from db using mapWith property. 你将不得不要么设置dbCreate模式, none在您的DataSource.groovy或从数据库中使用删除doamin的映射mapWith财产。

But if you still want to have a Doamin class that fetches data from a view then you can look into this answer . 但是,如果您仍然想拥有一个从视图中获取数据的Doamin类,那么您可以调查这个答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM