当同一个表用于多个hasMany关系时,“Grails在实体映射中重复列”错误

时间:2015-12-06 01:50:00

标签: entity-framework hibernate grails gorm grails-2.3

我有公共表(entity_notes)来保存系统中所有实体的注释,它有entity_id,entity_type_id列来标识注释所属的实体。以下是我的grails域名。

class EntityType {
    String name
    String code
    Boolean active
}

class EntityNotes  {

    EntityType entityType
    Long entityId
    String notes
    NoteType type

    static mapping = {
        table 'Entity_Notes'
        id generator: 'identity'
        version false
        entityId column:'entity_id'
    }
 }

 class Customer {
      static hasMany = [entityNotes: EntityNotes]
      static mapping = [
         table 'Customer'
         id generator: 'identity'
         version false
         entityNotes column:'entity_id', joinTable: false
      ]
      static hibernateFilters = {
         notesFilter(condition: 'entity_type_id=1', collection:'entityNotes', default: true)
      }
 }

 class Order {
      static hasMany = [entityNotes: EntityNotes]
      static mapping = [
         table 'Order'
         id generator: 'identity'
         version false
         entityNotes column:'entity_id', joinTable: false
      ]
      static hibernateFilters = {
         notesFilter(condition: 'entity_type_id=2', collection:'entityNotes', default: true)
      }
 }

如果只有一个hasMany到EntityNotes,它的工作正常。但是当我有两个具有相同hasMany的域时,它会抛出MappingException。

"org.hibernate.MappingException: Repeated column in mapping for entity: com.mycompany.domain.EntityNotes column: entity_id (should be mapped with insert="false" update="false")"

0 个答案:

没有答案