Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create sequence before table #100

Open
make opened this issue Nov 2, 2016 · 2 comments
Open

Create sequence before table #100

make opened this issue Nov 2, 2016 · 2 comments

Comments

@make
Copy link

make commented Nov 2, 2016

I am using following domain class mapping to enable direct SQL inserts.

class Foo {
    static mapping = {
        id defaultValue:"nextval('seq_foo')"
    }
}

When using dbCreate = 'update' in datasource table and sequence are automatically created when running 'grails run-app'.
The problem is that table is created first and causes error:

[main] ERROR o.h.tool.hbm2ddl.SchemaUpdate - ERROR: relation "seq_foo" does not exist

The workaround is to rerun "grails run-app".

Sequence should be created before table to fix that issue.

@ilopmar
Copy link
Collaborator

ilopmar commented Nov 2, 2016

Maybe I'm missing something but why are you doing this? When you say to enable direct SQL inserts you mean to be able to do an insert without setting a value for the id column?

@make
Copy link
Author

make commented Nov 15, 2016

Yes. I want to enable both manual SQL inserts and GORM inserts using the same auto-incrementing id sequence.

So mapping id defaultValue:"nextval('seq_foo')" should be declared to enable following to work

new Sql(dataSource).executeInsert('INSERT INTO foo DEFAULT VALUES')

Equal GORM insert is

new Foo().save(flush:true)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants