"Grails Repeated column in mapping for entity" error when same table is used for multiple hasMany relations

679 views Asked by At

I have common table (entity_notes) to hold notes for all entities in my system, It had entity_id, entity_type_id columns to identify to which entity the notes belong to. So below are my grails domains.

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)
      }
 }

If there is only one hasMany to EntityNotes, its working fine. But when i have two Domains with same hasMany it is throwing a 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

There are 0 answers