2021-01-06 21:06

Schema validation fails on SQL Server 2012 and Oracle - Hibernate bug

Task List

  • [x ] Steps to reproduce provided
  • [x ] Stacktrace (if present) provided
  • [ ] Example that reproduces the problem uploaded to Github
  • [ ] Full description of the issue provided (see below)

Steps to Reproduce

  1. Create a basic application using Grails 3.3.0
  2. Create a simple domain class with just one field
  3. Add "provided 'com.microsoft.sqlserver:sqljdbc4:4.0'" to "build.gradle"
  4. Set the datasource using "dbCreate: update" and "dialect: org.hibernate.dialect.SQLServer2012Dialect"
  5. Run the application and let Grails creates the table
  6. Stop the application and set "dbCreate" to "validate"
  7. Re-run the application

Expected Behaviour

I'm expecting the application starts correctly, by validating the table just created.

Actual Behaviour

The application fails to start, reporting schema validation error: the validation process can't find the table previously created (Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table)

Environment Information

  • Operating System: Win10 x64
  • Grails Version: 3.3.0 (GORM 6.1.6.RELEASE)
  • JDK Version: 1.8 update 131 x64
  • Container Version (If Applicable): Embedded tomcat



  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • weixin_39818014 weixin_39818014 4月前
    点赞 评论 复制链接分享
  • weixin_39989668 weixin_39989668 4月前

    👍 ran into the same issue - had to set dbCreate to 'none' as a workaround (skipping validation).

    点赞 评论 复制链接分享
  • weixin_39957805 weixin_39957805 4月前

    Upload an example project

    点赞 评论 复制链接分享
  • weixin_39818014 weixin_39818014 4月前

    Hi , I can't provide an example at the moment (in these days I'm using a PC not mine and without Grails because I'm not at work), but you can create an example by following the steps provided above.

    点赞 评论 复制链接分享
  • weixin_39716800 weixin_39716800 4月前

    Doesn't seem that the problem is specific to Grails 3.3

    I setup SQL Server with Docker and both Grails 3.2 (with GORM 6) and Grails 3.3 (with GORM 6.1) produce the same exception.

    In debugging no tables are returned from the JDBC metadata so Hibernate throws an exception. I am unsure why the SQL server Java driver are not returning the table metadata. The issue has also been reported against Oracle it seems #10768

    Seems like a Hibernate bug to me, not sure what we can do about it.

    点赞 评论 复制链接分享
  • weixin_39716800 weixin_39716800 4月前

    https://hibernate.atlassian.net/browse/HHH-11440 seems related

    点赞 评论 复制链接分享
  • weixin_39716800 weixin_39716800 4月前

    Problem can be resolved by configuration in application.yml:

          jdbc_metadata_extraction_strategy: individually

    I guess we may need to make this the default.

    点赞 评论 复制链接分享
  • weixin_39963465 weixin_39963465 4月前

    According to https://hibernate.atlassian.net/browse/HHH-11440 it has been fixed in Hibernate 5.1.13 can you please upgrade your Hiberate dependency to compile "org.hibernate:hibernate-core:5.1.13.Final" and let us know if it works without the workaround?

    点赞 评论 复制链接分享
  • weixin_39818014 weixin_39818014 4月前

    thanks a lot, I'll try ASAP

    点赞 评论 复制链接分享
  • weixin_39682511 weixin_39682511 4月前

    Just an FYI - I tried the workaround with Hibernate 5.1.5 (default for Grails 3.3.8) and I tried using Hibernate 5.1.13 with Grails 3.3.8 and both seem to work correctly.

    Hopefully Grails 3.3.9 and above will use a newer version of Hibernate so this issue goes away!

    点赞 评论 复制链接分享
  • weixin_39963465 weixin_39963465 4月前

    I have an open PR to upgrade Hibernate to 5.1.16.Final that will be included in Grails 3.3.9: https://github.com/grails/grails-core/issues/11065

    点赞 评论 复制链接分享
  • weixin_39713833 weixin_39713833 4月前

    and , both the workaround described above and the upgrade to Hibernate 5.1.13 worked like a charm here. I'm using Grails 3.3.6 with SQL Server 2017 (docker for Linux). Thank you very much.

    点赞 评论 复制链接分享