使用复合ID时,会向同一个域类发出多个hasMany关系

时间:2009-07-24 22:37:56

标签: grails groovy gorm

我收到此异常: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的任何建议吗?

1 个答案:

答案 0 :(得分:0)

如果您想从班级中创建一对多。在类类添加的Cells类中属于可以处理它的房间....

  • 哈尔吉特