我在运行 grails run-app
时收到此错误:
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
) 时,会发生此错误:
执行 Bootstrap 时出错:创建名称为“messageSource”的 bean 时出错:bean 初始化失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为“transactionManager”的bean时出错:设置bean属性“sessionFactory”时无法解析对bean“sessionFactory”的引用;嵌套异常是org.springframework.beans.factory.BeanCreationException:创建名称为“sessionFactory”的bean时出错:调用init方法失败;嵌套异常是java.lang.InknownClassChangeError:找到类org.hibernate.cfg.Mappings,但需要接口(interface)
有人知道如何处理这个问题吗?
(错误报告的形式为 http://jira.grails.org/browse/GRAILS-7994 )
最佳答案
这是 Joda Time 插件中的一个错误。请参阅提到的JIRA issue了解详情。
关于database - 如何避免 'Could not determine Hibernate dialect for database name [H2]!' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7336107/