Search code examples
grailsgrails-ormgrails-domain-class

Mapping Grails Domain object to JDBC table/sequence


I am trying to map an existing oracle table to a new Grails Domain Object. I also have an existing sequence. When calling "run-app", I get an error:

Unsuccessful: create sequence hibernate_sequence
ORA-01031: insufficient privileges

My goal is to use the existing sequence, and not create a new one. For the record, this is my first Grails/Groovy attempt.

My domain object looks like below. Table name is Uicc_Inv_Detail. PK is UICC_INV_DETAIL_ID. Other columns are the same name as in Uicc Class. Sequence name is Uicc_Inv_Detail_Seq.
I assume my whole "id generator" section is wrong.

class Uicc {
  String id
  String iccid
  String imsi

  static mapping = {
    version false
    table 'Uicc_Inv_Detail'
    id generator: 'sequence',column:'UICC_INV_DETAIL_ID',
            params:  [table: 'Uicc_Inv_Detail_Seq', column: 'nextval']

  }

    static constraints = {
    }
}

Solution

  • Use:

    id generator:'native', params:[sequence:'Uicc_Inv_Detail_Seq']
    

    Here's the docs: http://grails.org/doc/2.0.x/ref/Database%20Mapping/id.html http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/mapping.html#mapping-declaration-id-generator