Scenario: Domain class is created and inserted using the default Postgres sequence generator (with a custom dialect to create one sequence per table but I think this is irrelevant). Now, in some cases I'd like to choose my own ID for insertion.
I imagine two basic ways:
- preferred: simply set the id in the domain prior saving. If it is not set, use a generated id. I naively tried this, but it didn't work, i.e. the instance is inserted with the auto generated id, even if another id is already set in the domain instance.
- using a "generator: assigned" mapping and determine a default id (let the DB decide). How to do this best?
OK, so finally I came up with this (basically a combination from diverse suggestions made by others at different points in time)
}
To use it specifically on a domain class, you would include something like
into your domain class definition, which also allows to specify an id pool and its size. Seems to run great so far :)