Search code examples
grails

Override default sequence name in Grails


How can I rename HIBERNATE_SEQUENCE? Methods for generating one sequence per table (and giving specific names to those sequences) are well-documented, but that's not what I'm looking for.

I don't mind having one sequence shared by all domain classes. I just need to give it an application-specific name.


Solution

  • There appears to be an open feature / enhancement request in the Hibernate JIRA to make this globally configurable: Make the default sequence name globally configurable. I believe, as a workaround, you would have to set the 'generator' attribute to the same name for all domain classes (defaults to hibernate_sequence) for every @Id field. See oracle sequence created.

    As you hinted in your question, there might be a way to do this by subclassing your database dialect - as many have suggested for a sequence-per-table approach.

    See id generator and DRY principle