Reputation: 256
I am new in Grails. To connect with database just change username and password,add table name in dataSource.groovy file. The code is as follows:
dataSource {
pooled = true
jmxExport = true
driverClassName = "com.mysql.jdbc.Driver"
dialect = "org.hibernate.dialect.MySQLDialect"
username = "root"
password = ""
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
// cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
singleSession = true // configure OSIV singleSession mode
flush.mode = 'manual' // OSIV session flush mode outside of transactional context
}
// environment specific settings
environments {
development {
dataSource {
url = "jdbc:mysql://localhost/user"
username = "root"
password = ""
}
}
test {
dataSource {
url = "jdbc:mysql://localhost/user_prod"
username = "root"
password = ""
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost/user_prod"
username = "root"
password = ""
}
}
}
After click on run as button facing the following error :
Line | Method
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
Caused by 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 org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.ehcache.EhCacheRegionFactory]
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.ehcache.EhCacheRegionFactory]
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
Caused by HibernateException: could not instantiate RegionFactory [org.hibernate.cache.ehcache.EhCacheRegionFactory]
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
Caused by ClassNotFoundException: org.hibernate.cache.ehcache.EhCacheRegionFactory
->> 156 | findClass in org.codehaus.groovy.tools.RootLoader
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 423 | loadClass in java.lang.ClassLoader
| 128 | loadClass in org.codehaus.groovy.tools.RootLoader
| 356 | loadClass in java.lang.ClassLoader
| 186 | forName . in java.lang.Class
| 334 | innerRun in java.util.concurrent.FutureTask$Sync
| 166 | run . . . in java.util.concurrent.FutureTask
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run in java.lang.Thread
Upvotes: 0
Views: 273
Reputation: 75671
The problem is in this line:
Caused by ClassNotFoundException: org.hibernate.cache.ehcache.EhCacheRegionFactory
When things go boom in Grails, you tend to get rather large stacktraces that can hide the real problem. As large as that one is, it's probably only 10-20% of the real stack, since many obviously unhelpful stack frames are excluded by default. But in general, you'll often see a chain of exceptions, with the exception that caused the current one displayed below. So it's best to read from the bottom up, since that's usually the core problem.
I'm not sure why the ehcache dependency would be missing - did you exclude it in BuildConfig.groovy? You can add in a dependency:
dependencies {
...
compile 'net.sf.ehcache:ehcache-core:2.4.8'
}
and see if that helps.
EDIT
Actually no - that's not the problem since it's referencing a Hibernate class that works with Ehcache, not an Ehcache class. So it's a Hibernate v3 / v4 issue. Grails now defaults to Hibernate 4.x but includes the config settings to use Hibernate 3.x. You apparently switched to Hibernate 3 in BuildConfig.groovy, but didn't update the datasource configuration in DataSource.groovy
- comment out
cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
and use this instead:
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
Upvotes: 2
Reputation: 7723
newbee . Welcome to Grails.
You problem/s are as follow and measures you have to take
This error you see comes from diffrent reasons:
transactionManager ,sessionfactroy
1. Is please make sure you are running MySQL instance first and the port also.
2. Check that the password and the user name are correct and works to connect to the mysql console.
3. Make sure the (UserProd) MySQL database exists ,
check this setting for cache , revert it if uhave changed anything around there ?
cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
Upvotes: -1