繁体   English   中英

使用复合ID时多个hasMany与同一个域类有关系的问题

[英]Issue with multiple hasMany relationships to the same domain class when using composite id

我收到此异常: org.hibernate.MappingException: collection foreign key mapping has wrong number of columns: Room.cellsOrig type: component[locationX,locationY]

class Room implements Serializable {
    Integer locationX;
    Integer locationY;
    List cellsOrig = []
    List cells = []

    static hasMany = [cellsOrig: Cell, cells: Cell]
    static mapping = { id composite['locationX', 'locationY']
        cells joinTable:'room_cells'
        cellsOrig joinTable:'room_cells_orig'
    }
    static constrants = { locationX(nullable: false) locationY(nullable: false)   
        cells(nullable: false) cellsOrig(nullable: false) 
    }
}

我认为我做错了joinTable,但是如果没有joinTables,对Room实例的cell或cellOrig属性的任何访问都会导致org.hibernate.HibernateException: null index column for collection: Room.cells

关于如何以可处理复合ID的方式执行joinTable的任何建议?

如果要从该类中创建一对多。 在一个类添加的Cells类中,它属于负责该房间的Room ....

  • 哈吉特

暂无
暂无

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

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