kaleidos / grails-postgresql-extensions

Grails plugin to use postgresql native elements such as arrays, hstores,...
Apache License 2.0
78 stars 63 forks source link

How to set the default sequence name in grails 3.x version back to grails 2.x pattern? #101

Closed edwardotis closed 7 years ago

edwardotis commented 7 years ago

The default sequence name pattern has changed from grails 2 to 3, and this breaks the database migration plugin diffs. I have to manage the name by hand for each Domain class now.

Is there a way to set the default sequence naming pattern in Grails 3.x back to the 2.x style, so I don't have to manage this individually on each Domain class?

Thanks

-- Grails 2.x Hibernate 4 org.postgresql:postgresql:9.4.1207 postgresql-extensions:4.6.1

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

Results in: seq_

Grails 3.x Hibernate 4 org.postgresql:postgresql:9.4.1212 postgresql-extensions:4.6.8 grails.gorm.default.mapping = { id generator: 'native' }

Results in:

_id_seq
ilopmar commented 7 years ago

Hi.

There's a warning on the documentation about this: https://github.com/kaleidos/grails-postgresql-extensions#configuration. Obviously it's not enough, sorry about that. I'm planning to migrate all the documentation to asciidoctor, so once I do that the warnings and notes should be easy to find.

image

The problem is with Hibernate 5.1. They have changed the way the sequence name is generated, so I'm afraid we can't do anything about it. Those changes are included in version 5.0.0 so if you're using 4.6.8 (that supports Hibernate 4 but not 5) the behavior should be the previous one.

edwardotis commented 7 years ago

Hi,

Actually, I read the part about hibernate 5. I realize I did not give enough info on my hibernate config. I'm still using hibernate 4 for both versions, though the library versions have been updated.

Old: grails 2.5.5 liquibase database-migration:1.4.1 org.postgresql:postgresql:9.4.1207 postgresql-extensions:4.6.1 hibernate4:4.3.10 org.jadira.usertype:usertype.core:4.0.0.GA Postgres 9.5 Java 8 Ubuntu 14.04LTS

New grails 3.1.14 runtime 'org.grails.plugins:database-migration:2.0.0' compile 'org.liquibase:liquibase-core:3.5.3 org.postgresql:postgresql:9.4.1212 postgresql-extensions:4.6.8 compile "org.grails.plugins:hibernate4:5.0.12" compile "org.hibernate:hibernate-core:4.3.11.Final" compile "org.hibernate:hibernate-ehcache:4.3.11.Final", { exclude module: 'ehcache-core' } compile("org.jadira.usertype:usertype.core:4.0.0.GA") { exclude group: 'org.hibernate', module: 'hibernate-entitymanager' } //BEGIN spring-security-ui depends on explicit hibernate4:5.0.x compile 'org.grails:grails-datastore-core:5.0.12.RELEASE' compile 'org.grails:grails-datastore-gorm-support:5.0.12.RELEASE' compile 'org.grails:grails-datastore-gorm:5.0.12.RELEASE' compile 'org.grails:grails-datastore-simple:5.0.12.RELEASE' compile 'org.grails:grails-datastore-gorm-hibernate4:5.0.12.RELEASE' compile 'org.grails:grails-datastore-gorm-hibernate-core:5.0.12.RELEASE' Postgres 9.5 Java 8 Ubuntu 14.04LTS

ilopmar commented 7 years ago

Could you please create a sample project with Grails 3.1.14 that reproduces the issue? The version 4.6.8 it's not compatible with Hibernate 5 and the sequence changes has not been applied:

https://github.com/kaleidos/grails-postgresql-extensions/blob/4.x/src/main/groovy/net/kaleidos/hibernate/PostgresqlExtensionsDialect.groovy#L73

edwardotis commented 7 years ago

@ilopmar Thanks for finding that diff. Upon further investigation, this is almost certainly due to a bug in liquibase that is improperly re-generating changesets on existing schemas. I see that the initial generation of the sequence name uses proper hibernate4 pattern. The needless re-generation of the sequence uses the wrong pattern. So, everything looks fine with the grails-postgresql-extensions plugin. Thanks for your help.

For reference:

https://github.com/grails-plugins/grails-database-migration/issues/100

https://github.com/grails-plugins/grails-database-migration/issues/95

https://github.com/liquibase/liquibase-hibernate/issues/134

ilopmar commented 7 years ago

Thank you!