如何避免“无法确定数据库名称 [H2] 的 Hibernate 方言!"? [英] How do I avoid 'Could not determine Hibernate dialect for database name [H2]!'?

查看:16
本文介绍了如何避免“无法确定数据库名称 [H2] 的 Hibernate 方言!"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行 grails run-app 时遇到这个错误:

I am getting this error when running grails run-app:

执行引导程序时出错:创建带有名称的 bean 时出错'messageSource': bean 初始化失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:错误创建名为transactionManager"的 bean:无法解析引用在设置 bean 属性 'sessionFactory' 时为 bean 'sessionFactory';嵌套异常是org.springframework.beans.factory.BeanCreationException:错误创建名为sessionFactory"的 bean:无法解析对的引用设置 bean 属性时 bean 'hibernateProperties''休眠属性';嵌套异常是org.springframework.beans.factory.BeanCreationException:错误创建名为hibernateProperties"的 bean:无法解析设置 bean 属性时引用 bean 'dialectDetector'带有键 [hibernate.dialect] 的属性";嵌套异常是org.springframework.beans.factory.BeanCreationException:错误创建名为dialectDetector"的 bean:调用 init 方法失败的;嵌套异常是org.codehaus.groovy.grails.orm.hibernate.exceptions.CouldNotDetermineHibernateDialectException:无法确定数据库名称 [H2] 的 Hibernate 方言!

Error executing bootstraps: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.codehaus.groovy.grails.orm.hibernate.exceptions.CouldNotDetermineHibernateDialectException: Could not determine Hibernate dialect for database name [H2]!

根据DataSource.groovy:

dataSource {
  pooled = true
  driverClassName = "org.h2.Driver"
  username = "sa"
  password = ""
  // Adding this causes a different error:
  // dialect = org.hibernate.dialect.H2Dialect
}

hibernate {
  cache.use_second_level_cache = true
  cache.use_query_cache = true
  cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
}

environments {
  development {
    dataSource {
      dbCreate = "create-drop" // one of 'create', 'create-drop','update'
      url = "jdbc:h2:mem:devDB"
    }
  }
  test { // test-related stuff }
  production { // prod-related stuff }
}

当我明确提供上述方言(org.hibernate.dialect.H2Dialect)时,就会出现这个错误:

When I explicitly provide the dialect as stated above (org.hibernate.dialect.H2Dialect), then this error occurs:

执行引导程序时出错:创建名为messageSource"的 bean 时出错:bean 初始化失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为transactionManager"的 bean 时出错:设置 bean 属性sessionFactory"时无法解析对 beansessionFactory"的引用;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为sessionFactory"的 bean 时出错:调用 init 方法失败;嵌套异常是 java.lang.IncompatibleClassChangeError: Found class org.hibernate.cfg.Mappings, but interface was expected

Error executing bootstraps: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError: Found class org.hibernate.cfg.Mappings, but interface was expected

有人知道如何应对吗?

(错误报告存在为 http://jira.grails.org/browse/GRAILS-7994)

推荐答案

这是 Joda 时间插件中的一个错误.有关详细信息,请参阅上述 JIRA 问题.

This was a bug in the Joda Time Plugin. See the mentioned JIRA issue for details.

这篇关于如何避免“无法确定数据库名称 [H2] 的 Hibernate 方言!"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆