Grails: Foreign key as primary key?

核能气质少年 提交于 2019-12-23 05:57:08

问题


first of all i have to say that i have an existing database that it can not be modify (that´s why i am having this problem)

I have two cases, the first one is this: In this case the id (primary key) must be a foreign key as well. The code that i put, it doesn´t work.

class SbPEstadoComponente {

    static mapping = {
         table 'SB_P_ESTADO_COMPONENTE'         
         version false
         idEstadoComponenteHxPEstado column:'ID_ESTADO_COMPONENTE'
     id column:'ID_ESTADO_COMPONENTE'
    }

    // Relation
    SbPDemora idEstadoComponenteHxPEstado
    String facturable
    ..
    ..
    ..
}

In the other case the table has 3 columns, that coluns are foreign key to 3 tables. Also those 3 columns have to be a composite primary key.

Any ideas? sugestions? Thanks a lot !!


回答1:


In your child class's mapping you need id composite: ['fkey1', 'fkey2'] and implements Serializable

Note that when you do a get you will need to populate all the composite key values



来源:https://stackoverflow.com/questions/4936542/grails-foreign-key-as-primary-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!