Grails con Oracle-DB: parece tener solo un contador global para ID

when I use hsqldb with grails, it seems that each domain class gets its own counter for the id autoincrement. When I create an object of type a, it gets ID=1. When I then create an object of type b, it gets ID=1. When I then create an object of type a again, it gets ID=2.

That's the behaviour I expect.

when I use an oracle db it seems that there is only one global counter for all IDs of all domain classes. When I create an object of type a, it gets ID=1. When I then create an object of type b, it gets ID=2. When I then create an object of type a again, it gets ID=3.

¿Cómo puedo cambiar esto?

preguntado el 08 de enero de 11 a las 21:01

2 Respuestas

Grails is using hibernate and by default hibernate is using only one sequence to generate all ids. If you need one sequence per table you can edit Config.groovy. Add following line:

grails.gorm.default.mapping = {id generator:'identity'}

Respondido 08 Jul 14, 11:07

La 'identity' generator type is not supported for Oracle databases. Docs for Hibernate 3 and 4 both state: "identity supports identity columns in DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL." There's no Oracle. I tried nevertheless and, as expected, it didn't work. How come this is accepted answer with 4 upvotes? Am I missing something? - cuajada0

If you want to have more control of how the database is generated/updated then it is better to use a database migration then letting Hibernate manage it. We use Liquibase which is very easy to use and flexible and there is already a Grails plug in for it. Also, if I am not mistaken database migrations are going to be integrated in Grails core for version 1.4 so you will be able to use schema migrations without having to install any plug in.

Respondido el 09 de enero de 11 a las 23:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.