Friday, October 25, 2013

Grails GORM mapping id column using sequence

I work with grails 2.2.4 and legacy database. The legacy database is using postgreSQL. The primary key filed is hdsj_id (bigserial).


class TableHeaderSuratJalan {

 // a lot of field
 ...

 static mapping = {
  id column: "hdsj_id", generator: "sequence", params: [sequence:"table_header_surat_jalan_hdsj_id_seq"]
  version false
 }

}



We need to specify the sequence name, in this example my sequence's name is table_header_surat_jalan_hdsj_id_seq. By default grails will use hibernate_sequence

No comments:

Post a Comment