0

I'm trying to get a generator to work for both the id column and use another sequence for a different, non-id column.

This doesn't seem to do anything. The column is still null after doing a save (in integration tests).

   static mapping = {
      id generator: 'sequence', params: [sequence: 'id_seq']
      otherCol generator: 'sequence', params: [sequence: 'other_seq']
      version true
   }
Sean LeBlanc
  • 185
  • 2
  • 12

2 Answers2

1

To my knowledge, the generator option only works for id columns. It is based on Hibernate @GeneratedValue which is always used in conjunction with the @Id annotation.

See:

http://grails.github.io/grails-doc/3.0.x/guide/single.html#identity

http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/mapping.html#mapping-declaration-id-generator

Hibernate JPA Sequence (non-Id)

Community
  • 1
  • 1
Azocan Kara
  • 253
  • 2
  • 8
0

One possible solution would be to use the sequence-generator plugin for grails. As i understand it, it emulates the behavior of a database sequence because of the restriction of the grails / hibernate generators.

I had a pretty similar problem and this plugin solved it. It has some additional features like that you can define a prefix for a sequence.

Mario David
  • 1,595
  • 11
  • 19
  • Thanks, I stumbled across this when looking around for a solution to my original question. Does it support using database sequences, however? – Sean LeBlanc Apr 30 '15 at 16:13
  • From the [docs](https://github.com/goeh/grails-sequence-generator#annotation-sequenceentity), it says that the plugin does not use database sequences, because of the lack of flexibility that the plugin want's to achieve. Nevertheless you can at least db unique settings. – Mario David May 01 '15 at 18:35