1
votes

Does anyone knows if there's a way for Grails to check if a referential constraint he is trying to create already exists?

Unfortunately, I can't drop the database and create it again, because of the enviroment in wich it is and my company policy, size of the database, etc.

It throws me an error that I would not want it to exist in production enviroment:

[main] ERROR hbm2ddl.SchemaUpdate  - Unsuccessful: alter table <TABLE> add constraint <CONSTRAINT> foreign key (<FK>) references <THEOTHERTABLE>
[main] ERROR hbm2ddl.SchemaUpdate  - ORA-02275: such a referential constraint already exists in the table.

Edit: This happened when I tried to correct the name of a Table column that is a foreign key from another table.

Oracle 10g Grails 1.3.9

4
Are you doing this with the database migrations plugin?James Kleeh
No. Sorry, I added more information about why this happened.Johnny C.

4 Answers

2
votes

Use hibernate.hbm2ddl.auto=validate. This will not try to makes any change in your schema, just "validate" what you map in your POJOs with the database schema.

Also you can set your logger to "debug" level and you will check what Hibernate is doing.

0
votes

I think, for now, this works for me, I won't mark it as the answer if anyone else knows something more about it. But what I did is this:

In Testing and Production enviroment I remove the "dbCreate" instrucción from my DataSource.groovy, this way Grails (Hibernate) doesn't try to create anything and just use what he finds.

This works for me because in these enviroments my grails DB User dosen't have any privilegies to create anything, so its useless for it to even try.

0
votes

I encountered this error because of the line in application.properties

spring.jpa.generate-ddl = true

This tries to generate sql foreign keys for mappings. If you have configured foreign key relations in database, this configuration line will try to override it. Removing this line from application properties has solved my problem.

0
votes

remove spring.jpa.hibernate.ddl-auto=update from application.properties