GORM two fields mapped to one throw column exception ... insert = "false" update = "false"

I have two classes, one of which is associated with the other (this is a one-to-one relationship). Both of them share the primary key.

One belongs to another ( belongs to To ), the other has one parent ( hasOne ).

Something like that:

class Parent {
    int id
    static hasOne = [ child : Child ]         
}

class Child {
    int id
    static belongsTo = [ parent: Parent ]
    static mapping = {
        parent column: 'id'
    }
}

This does not work!:(

+4
source share
1 answer

I found the answer, the HB error is pretty clear, but in GORM, how you do it is different.

. , , Hibernate ( GORM), .

Child

class Parent {
    int id
    static hasOne = [ child : Child ]         
}

class Child {
    int id
    static belongsTo = [ parent: Parent ]
    static mapping = {
        parent column: 'id', insertable: false, updateable: false
    }
}

, .:)

+6

All Articles