0
votes

I'm trying to connect a lagacy database and I'm having some troubles. I'm using Grails 3.2.3 and Postgresql 9.4. When a try to change the column name, GORM create the column twice, one time with the name i choose and the other with GORM column name format. The column is estado in Cidade entity and I need to map it to "EstadoId".

It creating both: "EstadoId" integer NOT NULL estadoid integer NOT NULL,

class Cidade {
  int id
  String nome
  Boolean capital

  static mapping = {
    table '`tbCidades`'
    id column: '`CidadeId`'
    nome column: '`Nome`'
    capital column: '`Capital`'
    estado column:  '`EstadoId`'
    version false
  }

  static belongsTo = [ estado : Estado]
}

class Estado {
  int id
  String sigla

  static hasMany = [ cidades: Cidade ]

  static mapping = {
    table '`tbEstados`'
    id column: '`EstadoId`'
    sigla column: '`Sigla`'
    version false
  }
}

I noticed with I choose a name using underscore format (Like: my_column_estado it works.)

1

1 Answers

0
votes

It's default bahaviour of grails; when you use

static belongsTo = [ estado : Estado]

it's creating estado_id column which is mapping to estado instance. Have you try to remove constraint:

estado column: 'EstadoId'

drop test db and recompile project?