简体   繁体   中英

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,526 [Thread-11] ERROR hbm2ddl.SchemaUpdate - HHH000299: Could not complete schema update

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.

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. 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. 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.

But if you still want to have a Doamin class that fetches data from a view then you can look into this answer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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