I am getting this error when running 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]!
The according 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 }
}
When I explicitly provide the dialect as stated above (org.hibernate.dialect.H2Dialect
), then this error occurs:
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
Anyone know how to cope with this?
(Bug-report exists as http://jira.grails.org/browse/GRAILS-7994)
If jdk is Java 7u25 and grails 2.2.1, may be a solution:: Grails suddenly throws error Could not determine Hibernate dialect for database name
The information that the error is fixed in grails 2.2.3 is correct. I tested it and it worked. A point to be made is (Spring loaded causes Grails to fail to bootstrap using Oracle JDK 1.7u25):
I hope you find it useful :)
It seems that the problem is related to the version of JDK 7 (openjdk 7u25).
Alternative is to use Ubuntu PPA for Oracle JDK: https://launchpad.net/~webupd8team/+archive/java
which worked fine for me and solved the problem.
This was a bug in the Joda Time Plugin. See the mentioned JIRA issue for details.
Which version of Grails are you using? I believe you are using Grails 1.3.7.
The H2Dialet has a few bugs from the Hibernate.jar which is 3.3.1 in Grails 1.3.7, it is included in Hibernate 3.5 and Grails 2.0.
My solution is, in your DataSource.groovy, use this
and download the Java class from here : Source Code, change its class name to H2DialectPatch to avoid confusing, put it in your src/java folder.
I just upgraded to Grails 2.0, and was experiencing the same issue, but if I created a brand new Grails 2.0 project there were no such problems. I leave this answer for any who might be experience the same. It's important to ensure the right hibernate libraries are being used.
If like me you were upgrading an existing project, I recommend comparing the config files of your existing project with those of a brand new 2.0 project. Doing this you will see that the build config file should include a hibernate plugin: