Using Database Views in Grails

时间:2019-04-08 13:06:06

标签: grails grails-domain-class

I have created a view in my DB Postgres. In grails create a class as follows:

class ViewDeudce{

    BigDecimal stateid
    BigDecimal motivid

    static mapping = {
        id column:"id", sqlType:"numeric"
        table 'viewDeudce'
        version false
    }
}

The id of the view is the "client number". If I have a "Client" class, when doing this, I should not be able to relate it?:

class Clients implements Serializable {

    String name
    BigDecimal document
    String brutos

    ViewDeudce viewDeudce

static mapping = {
        id column:"idclient", sqlType:"numeric", generator: 'assigned'
        ViewDeudce column: "id", sqlType:"numeric"
        version false
    }

From what I understand, am I not telling the Client class to relate to the 'ViewDeudce' class via the id attribute?

Because when restarting the server, it does not start me and it gives me the following error:

Caused by BeanCreationException: Error creating bean with name '$ primaryTransactionManager': Can not resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ' sessionFactory ': Invocation of init method failed; nested exception is org.hibernate.HibernateException: Missing column: id in public.clients
- >> 266 | run in java.util.concurrent.FutureTask

Thanks!

1 个答案:

答案 0 :(得分:0)

也许尝试使用id而不是grails.domain类

class Clients implements Serializable {

    String name
    BigDecimal document
    String brutos

    //ViewDeudce viewDeudce
    //!!change here!!
    Long viewDeudceId

static mapping = {
        id column:"idclient", sqlType:"numeric", generator: 'assigned'
        ViewDeudce column: "id", sqlType:"numeric"
        version false
    }