0


My grails application uses h2 embedded database in production and recently I decided to upgrade it from grails 2.3 to 2.4. It went fine while in development mode, but after deploy to tomcat I mentioned that some things are broken, e.g there are problems with counting users, ApplicationContext fails to load my services with getBean etc. I checked the logs and found the following errors:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY KEY ON """".PAGE_INDEX"; SQL statement: ALTER TABLE PUBLIC.SHIRO_USER_ROLES ADD CONSTRAINT PUBLIC.FKBA2210573552FAD9 FOREIGN KEY(SHIRO_USER_ID) REFERENCES PUBLIC.SHIRO_USER(ID) NOCHECK [23505-176] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) at java.util.concurrent.FutureTask.run(FutureTask.java:166) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:701) Caused by: org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY KEY ON """".PAGE_INDEX"; SQL statement: ALTER TABLE PUBLIC.SHIRO_USER_ROLES ADD CONSTRAINT PUBLIC.FKBA2210573552FAD9 FOREIGN
KEY(SHIRO_USER_ID) REFERENCES PUBLIC.SHIRO_USER(ID) NOCHECK [23505-176] ... 6 more Caused by: org.h2.jdbc.JdbcSQLException: Unique index or primary key violation: "PRIMARY > KEY ON """".PAGE_INDEX"; SQL statement: ALTER TABLE PUBLIC.SHIRO_USER_ROLES ADD CONSTRAINT PUBLIC.FKBA2210573552FAD9 FOREIGN KEY(SHIRO_USER_ID) REFERENCES PUBLIC.SHIRO_USER(ID) NOCHECK [23505-176]

It looks like the H2 driver version has been updated in grails 2.4 and it is not compatible with the database scheme from the previous version. So what I can do about it? How do I migrate my database to the new H2 so it would work normally?

Artem Zhirkov
  • 157
  • 12

2 Answers2

0

You probably need to upgrade your database using this. Add this Jar to your classpath.

saw303
  • 8,051
  • 7
  • 50
  • 90
  • I included this jar into the lib folder of my grails application and tried to deploy. Pretty much nothing changed except that now my application not deploying at all. There is the complete log of tomcat bootstrap process http://files.develdynamic.com/catalina.out – Artem Zhirkov Jul 04 '14 at 12:26
  • I don't think it is a H2 problem. H2 is almost the same between Grails 2.3 and 2.4. New is that Grails uses Hibernate4 as default plugin. What did you use in Grails 2.3? – saw303 Jul 04 '14 at 12:36
  • I didnt upgrade hibernate to 4th version, I'm using 3.6.10. And I think it's actually a H2 problem because quite a similiar issue was discussed in the H2 mail list recently http://h2-database.66688.n3.nabble.com/Unique-index-or-primary-key-violation-quot-SYS-ID-ON-PUBLIC-SYS-ID-quot-23505-168-using-1-3-168-td4028700.html – Artem Zhirkov Jul 04 '14 at 12:45
-1

This is definitely a H2 issue. See this H2 thread where Thomas Mueller finds the issue.

Now what I need to figure out is how to exclude H2 version 176 from the Grails global and use 175, since anything after 176 is beta!