broken pipe exception with MySql in Grails app - mysql

I have deployed a Grails 2.2.1 application to a remote server. After a few hours, when I access to home page of the application, I see the following exception:
Error 500: Internal Server Error
URI
/DocGemStudioZoccali/
Class
java.net.SocketException
Message
Broken pipe
Trace
Line | Method
->> 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
Caused by GroovyPagesException: Error processing GroovyPageView: could not execute query; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query
->> 631 | runWorker in /index.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Caused by DataAccessResourceFailureException: could not execute query; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query
->> 108 | doCall in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 25 | doCall in gsp_docGemStudioZoccaliindex_gsp$_run_closure1
| 38 | run . . . in gsp_docGemStudioZoccaliindex_gsp
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run in java.lang.Thread
Caused by JDBCConnectionException: could not execute query
->> 108 | doCall in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 25 | doCall in gsp_docGemStudioZoccaliindex_gsp$_run_closure1
| 38 | run . . . in gsp_docGemStudioZoccaliindex_gsp
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run in java.lang.Thread
Caused by CommunicationsException: The last packet successfully received from the server was 138,684,859 milliseconds ago. The last packet sent successfully to the server was 138,684,859 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
->> 411 | handleNewInstance in com.mysql.jdbc.Util
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1116 | createCommunicationsException in com.mysql.jdbc.SQLError
| 3851 | send . . in com.mysql.jdbc.MysqlIO
| 2471 | sendCommand in ''
| 2651 | sqlQueryDirect in ''
| 2683 | execSQL in com.mysql.jdbc.ConnectionImpl
| 2144 | executeInternal in com.mysql.jdbc.PreparedStatement
| 2310 | executeQuery in ''
| 96 | executeQuery in org.apache.commons.dbcp.DelegatingPreparedStatement
| 108 | doCall in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2
| 25 | doCall . in gsp_docGemStudioZoccaliindex_gsp$_run_closure1
| 38 | run in gsp_docGemStudioZoccaliindex_gsp
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
Caused by SocketException: Broken pipe
->> 109 | socketWrite in java.net.SocketOutputStream
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 153 | write in ''
| 82 | flushBuffer in java.io.BufferedOutputStream
| 140 | flush in ''
| 3832 | send . . in com.mysql.jdbc.MysqlIO
| 2471 | sendCommand in ''
| 2651 | sqlQueryDirect in ''
| 2683 | execSQL in com.mysql.jdbc.ConnectionImpl
| 2144 | executeInternal in com.mysql.jdbc.PreparedStatement
| 2310 | executeQuery in ''
| 96 | executeQuery in org.apache.commons.dbcp.DelegatingPreparedStatement
| 108 | doCall in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2
| 25 | doCall . in gsp_docGemStudioZoccaliindex_gsp$_run_closure1
| 38 | run in gsp_docGemStudioZoccaliindex_gsp
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
I've tried to solve the problem as seen in another question in SO, but it does not work for me.
Here is what I've done inside config file:
dataSource {
dbCreate = "update"
url = "jdbc:mysql://urlofapp/myappname?useUnicode=yes&characterEncoding=UTF-8"
username = "root"
password = "root"
//run the evictor every 30 minutes and evict any connections older than 30 minutes.
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
//test the connection while its idle, before borrow and return it
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
Notice that, if I refresh the page, everything works correctly. Anybody knows something to solve this issue?
EDIT 1:
I've edited the my.cnf file in /etc folder, adding the following:
wait_timeout = 28800
interactive_timeout = 28800
but nothing changes
EDIT 2:
This is the actual data source that I'm using. Broken pipe still appears
dataSource {
dbCreate = "update"
url = "jdbc:mysql://urlofapp/myappname?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true"
username = "root"
password = "root"
minIdle = 5
maxIdle = 25
maxWait = 10000
maxAge = 10 * 60000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "SELECT 1"
validationQueryTimeout = 3
validationInterval = 15000
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
jdbcInterceptors = "ConnectionState;StatementCache(max=200)"
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}
EDIT 3:
Here is the stacktrace after the suggestion given by James Kleeh
2015-12-04 17:41:36,924 [http-bio-8080-exec-63] ERROR context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': 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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': 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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: 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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
2015-12-04 17:41:36,931 [http-bio-8080-exec-63] ERROR context.GrailsContextLoader - Error initializing Grails: Error creating bean with name 'transactionManagerPostProcessor': 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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': 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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: 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 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
... 3 more
Dec 04, 2015 5:41:36 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Dec 04, 2015 5:41:36 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/DocGemStudioTest] startup failed due to previous errors
2015-12-04 17:41:36,955 [http-bio-8080-exec-63] WARN lifecycle.ShutdownOperations - Error occurred running shutdown operation: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Dec 04, 2015 5:41:36 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/DocGemStudioTest] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
EDIT 4:
I've edited the properties block and now application starts. I need to check if error occurs after few hours.
properties{
minIdle = 5
maxIdle = 25
maxWait = 10000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "SELECT 1"
validationQueryTimeout = 3
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}

So I believe everything other than dbCreate, url, username, and password needs to be in a properties block:
dataSource {
dbCreate = "update"
url = "jdbc:mysql://urlofapp/myappname?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true"
username = "root"
password = "root"
properties {
minIdle = 5
maxIdle = 25
maxWait = 10000
maxAge = 10 * 60000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "SELECT 1"
validationQueryTimeout = 3
validationInterval = 15000
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
jdbcInterceptors = "ConnectionState;StatementCache(max=200)"
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}
}

Although, this should be strange but if the Grails app and the MySQL server both are on the same machine then use localhost or 127.0.0. instead of real IP address xxx.xxx.xxx.xxx
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost:3306/docgem_test_db?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true"
// Your other properties
}

Please try the below not the addition of driverClassName and dialect and I also added pooled in case you need that
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
dbCreate = "update"
url = "jdbc:mysql://urlofapp/myappname? useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true"
username = "root"
password = "root"
properties {
minIdle = 5
maxIdle = 25
maxWait = 10000
maxAge = 10 * 60000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "SELECT 1"
validationQueryTimeout = 3
validationInterval = 15000
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
jdbcInterceptors = "ConnectionState;StatementCache(max=200)"
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}
}

Looks to me like MySQL is timing out it's connection to you. Probably not much you can do about that.
Can you consider closing the connection if there's no traffic on it for a while and then re-open it when it's needed again?

Related

How to integrate mysql or mongodb to grails 3.2.10

I'm about start with a web application project and I am trying to integrate Mysql into Grails 3. All of the online tutorials show us to change the DataSource file which does not currently (there is Application.yml).
I tried changing the Application.yml as given in the official documentation, but it gives me a big error. Its a new project and has no other changes to it. I've used grails 2.4 previously, it was really easy with that and now I'm thinking of changing back.
Change:
dataSource :
pooled : true
dbCreate : "update"
url : "jdbc:mysql://localhost:3306/my_database"
driverClassName : "com.mysql.jdbc.Driver"
dialect : org.hibernate.dialect.MySQL5InnoDBDialect
username : "username"
password : "password"
properties :
jmxEnabled : true
initialSize : 5
maxActive : 50
minIdle : 5
maxIdle : 25
maxWait : 10000
maxAge : 10 * 60000
timeBetweenEvictionRunsMillis : 5000
minEvictableIdleTimeMillis : 60000
validationQuery : "SELECT 1"
validationQueryTimeout : 3
validationInterval : 15000
testOnBorrow : true
testWhileIdle : true
testOnReturn : false
jdbcInterceptors : "ConnectionState;StatementCache(max=200)"
defaultTransactionIsolation :
java.sql.Connection.TRANSACTION_READ_COMMITTED
the error I get:
/usr/lib/jvm/java-8-oracle/bin/java -XX:+TieredCompilation -
XX:TieredStopAtLevel=1 -XX:CICompilerCount=3 -Dfile.encoding=UTF-8 -
classpath /home/nischit/.gradle/caches/modules-2/files-
2.1/org.grails/grails-
shell/3.2.10/c6b000bbb8ac369a9be062f08e8a0a8d3f85705/grails-shell-
3.2.10.jar:/home/nischit/.gradle/caches/modules-2/files-
2.1/org.slf4j/slf4j-
simple/1.7.25/8dacf9514f0c707cbbcdd6fd699e8940d42fb54e/slf4j-simple-
1.7.25.jar:/home/nischit/.gradle/caches/modules-2/files-
2.1/org.codehaus.plexus/plexus-component-api/1.0-alpha-
33/7d9560effcadf867937ac6885d0d1045ea98ab59/plexus-component-api-1.0-
alpha-33.jar:/home/nischit/.gradle/caches/modules-2/files
Running application...
2017-10-02 01:42:14.120 ERROR --- [ost-startStop-1]
o.s.b.c.embedded.tomcat.TomcatStarter : Error starting Tomcat
context. Exception:
org.springframework.beans.factory.BeanCreationException. Message:
Error creating bean with name 'grailsCacheFilter': Cannot create
inner bean '(inner bean)#17d4fdc1' of type
[grails.plugin.cache.web.filter.
simple.MemoryPageFragmentCachingFilter]
while setting bean property 'filter'; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name '(inner bean)#17d4fdc1': Unsatisfied
dependency expressed through method 'setUrlMappingsHandlerMapping'
parameter 0; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'urlMappingsHandlerMapping':
Unsatisfied dependency expressed through method
'setWebRequestInterceptors' parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'openSessionInViewInterceptor': Cannot
resolve reference to bean 'hibernateDatastore' while setting bean
property 'hibernateDatastore'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'hibernateDatastore': Bean instantiation via
constructor failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.grails.orm.hibernate.HibernateDatastore]:
Constructor threw exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSource': Cannot resolve reference to
bean 'dataSourceLazy' while setting constructor argument; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSourceLazy': Cannot resolve
reference to bean 'dataSourceUnproxied' while setting constructor
argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at grails.boot.GrailsApp.run(GrailsApp.groovy:83)
at grails.boot.GrailsApp.run(GrailsApp.groovy:388)
at grails.boot.GrailsApp.run(GrailsApp.groovy:375)
at grails.boot.GrailsApp$run.call(Unknown Source)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.
defaultCall(CallSiteArray.java:48)
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'grailsCacheFilter': Cannot create
inner bean '(inner bean)#17d4fdc1' of type
[grails.plugin.cache.web.filter.simple.
MemoryPageFragmentCachingFilter] while setting bean property
'filter'; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name '(inner bean)#17d4fdc1': Unsatisfied
dependency expressed through method 'setUrlMappingsHandlerMapping'
parameter 0; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'urlMappingsHandlerMapping':
Unsatisfied dependency expressed through method
'setWebRequestInterceptors' parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'openSessionInViewInterceptor': Cannot
resolve reference to bean 'hibernateDatastore' while setting bean
property 'hibernateDatastore'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'hibernateDatastore': Bean instantiation via
constructor failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.grails.orm.hibernate.HibernateDatastore]:
Constructor threw exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSource': Cannot resolve reference to
bean 'dataSourceLazy' while setting constructor argument; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSourceLazy': Cannot resolve
reference to bean 'dataSourceUnproxied' while setting constructor
argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error c
reating bean with name 'dataSourceUnproxied': Initialization of bean
failed; nested exception is
org.springframework.beans.TypeMismatchException: Failed to convert
property value of type 'java.lang.String' to required type 'long' for
property 'maxAge'; nested exception is
java.lang.NumberFormatException: For input string: "10*60000"
at
org.springframework.beans.factory.support.
BeanDefinitionValueResolver.resolveInnerBean
(BeanDefinitionValueResolver.java:313)
Caused by:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name '(inner bean)#17d4fdc1': Unsatisfied
dependency expressed through method 'setUrlMappingsHandlerMapping'
parameter 0; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'urlMappingsHandlerMapping':
Unsatisfied dependency expressed through method
'setWebRequestInterceptors' parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'openSessionInViewInterceptor': Cannot
resolve reference to bean 'hibernateDatastore' while setting bean
property 'hibernateDatastore'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'hibernateDatastore': Bean instantiation via
constructor failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.grails.orm.hibernate.HibernateDatastore]:
Constructor threw exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSource': Cannot resolve reference to
bean 'dataSourceLazy' while setting constructor argument; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSourceLazy': Cannot resolve
reference to bean 'dataSourceUnproxied' while setting constructor
argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSourceUnproxied': Initialization of bean
failed; nested exception is
org.springframework.beans.TypeMismatchException: Failed to convert
property value of type 'java.lang.String' to required type 'long' for
property 'maxAge'; nested exception is
java.lang.NumberFormatException: For input string: "10*60000"
at
org.springframework.beans.factory.annotation.
AutowiredAnnotationBeanPostProcessor
$AutowiredMethodElement.inject
(AutowiredAnnotationBeanPostProcessor.java:667)
Caused by:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'urlMappingsHandlerMapping':
Unsatisfied dependency expressed through method
'setWebRequestInterceptors' parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'openSessionInViewInterceptor': Cannot
resolve reference to bean 'hibernateDatastore' while setting bean
property 'hibernateDatastore'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'hibernateDatastore': Bean instantiation via
constructor failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.grails.orm.hibernate.HibernateDatastore]:
Constructor threw exception; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSource': Cannot resolve reference to
bean 'dataSourceLazy' while setting constructor argument; nested
exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSourceLazy': Cannot resolve
reference to bean 'dataSourceUnproxied' while setting constructor
argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'dataSourceUnproxied': Initialization of bean
failed; nested exception is
org.springframework.beans.TypeMismatchException: Failed to convert
property value of type 'java.lang.String' to required type 'long' for
property 'maxAge'; nested exception is
java.lang.NumberFormatException: For input string: "10*60000"
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRun'.
Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with
non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info
or --debug option to get more log output.
| Error Failed to start server (Use --stacktrace to see the full
trace)
The problem is with the way you're trying to set the maxAge value on your data source:
Failed to convert property value of type 'java.lang.String' to
required type 'long' for property 'maxAge'; nested exception is
java.lang.NumberFormatException: For input string: "10*60000"
Try just setting a concrete value rather than a calculation.
If you are not very comfortable with YML standard then simply create a new file with name application.groovy, place it inside the conf directory and add the datasource block in that groovy file. Don't forget to remove the data source block from application.yml file.

How to use Hibernate Spatial in Grails?

I use Grails 2.4.5 and Hibernate 3.6.10.18 and want to use Hibernate Spacial with my MySql database.
Here is part of my BuildConfig.groovy:
repositories {
mavenRepo 'http://download.osgeo.org/webdav/geotools'
mavenRepo 'http://www.hibernatespatial.org/repository'
}
dependencies {
test "org.grails:grails-datastore-test-support:1.0.2-grails-2.4"
runtime 'mysql:mysql-connector-java:5.1.36'
compile 'org.hibernatespatial:hibernate-spatial:1.1.1'
compile 'org.hibernatespatial:hibernate-spatial-mysql:1.1.1'
compile 'com.vividsolutions:jts:1.13'
}
Refresh-dependencies works fine. But when I do. grails run-app I get the following error:
|Running Grails application
Error |
2015-07-17 21:00:05,471 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': 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.NoSuchMethodError: org.hibernate.mapping.PersistentClass.setJpaEntityName(Ljava/lang/String;)V
Message: Error creating bean with name 'transactionManagerPostProcessor': 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.NoSuchMethodError: org.hibernate.mapping.PersistentClass.setJpaEntityName(Ljava/lang/String;)V
Line | Method
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | 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 java.lang.NoSuchMethodError: org.hibernate.mapping.PersistentClass.setJpaEntityName(Ljava/lang/String;)V
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.mapping.PersistentClass.setJpaEntityName(Ljava/lang/String;)V
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Caused by NoSuchMethodError: org.hibernate.mapping.PersistentClass.setJpaEntityName(Ljava/lang/String;)V
->> 266 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1142 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 617 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
How do I resolve this error?
Found the solution here:
compile("org.hibernatespatial:hibernate-spatial:1.1.1") {
excludes("hibernate-core")
excludes("javassist")
}
compile("org.hibernatespatial:hibernate-spatial-mysql:1.1.1") {
excludes("hibernate-core")
excludes("javassist")
}

GRAILS: Using Domain subclasses

Using Grails with the following versions:
APPLICATION STATUS
App version: 0.1
Grails version: 2.3.5
Groovy version: 2.1.9
JVM version: 1.7.0_51
Reloading active: true
Controllers: 15
Domains: 18
Services: 2
Tag Libraries: 13
I have a domain model that I am trying to follow. I built the tables in MySQL prior to programming.
In the model, I have Insertion_orders that are bound to people (Persons) in a Many-to-Many relationship. This relationship is defined by Insertion_orders_persons, with the person_id & location_id defining an entry in Insertion_orders_persons. In addition there is a type value that is ENUMed either Trafficker, Advertiser, Agency, (or) Salesperson. One (or more) trafficker will always appear, but the rest may, may not or have many of these associations. I am trying to bind them according to type to the Insertion_orders model:
package cms
class Insertion_orders {
String insertion_order_name
String po_number
String notes
String toString() {
"${insertion_order_name} - ${id}"
}
static hasMany = [trafficker: Insertion_orders_traffickers, salesperson: Insertion_orders_salespersons]
static constraints = {
insertion_order_name(blank:false)
po_number()
notes(widget: 'textarea', nullable:true)
}
static mapping ={
version false
id column: 'insertion_order_id'
notes sqlType: 'text'
}
}
I am trying to use inheritance and a discrimiator value to accomplish this.
package cms
class Insertion_orders_persons {
Persons person
Insertion_orders insertion_order
Type type
String toString() {
"${person}: ${type}"
}
enum Type {
Trafficker, Salesperson, Advertiser, Agency
}
static constraints = {
}
static mapping = {
version false
id column: 'insertion_order_person_id'
discriminator column: "type"
}
}
class Insertion_orders_traffickers extends Insertion_orders_persons {
static mapping ={
discriminator value: "Traffickers"
}
}
class Insertion_orders_salespersons extends Insertion_orders_persons {
static mapping ={
discriminator value: "Salesperson"
}
}
The problem is that when I try to join to the extended classes (as in the hasMany in the Insertion_orders class), the Grails fails to start and generates the following:
|Loading Grails 2.3.5
|Configuring classpath
.
|Environment set to development
.................................
|Packaging Grails application
..........................................
|Running Grails application
Error |
2014-04-16 11:33:58,693 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': 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 org.hibernate.MappingException: Association references unmapped class: cms.Insertion_orders_salespersons
Message: Error creating bean with name 'transactionManagerPostProcessor': 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 org.hibernate.MappingException: Association references unmapped class: cms.Insertion_orders_salespersons
Line | Method
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | 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.MappingException: Association references unmapped class: cms.Insertion_orders_salespersons
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Association references unmapped class: cms.Insertion_orders_salespersons
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Caused by MappingException: Association references unmapped class: cms.Insertion_orders_salespersons
->> 262 | run in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Error |
Forked Grails VM exited with error
As additional information, regardless of how I try to access the subclasses, or the subclass composition, I get the same error.
This seems like a very fundamental functionality. Can someone please tell me what I am missing or doing incorrectly?
If you remove discriminator column: “type” from Insertion_orders_persons and define Insertion_orders_persons, Insertion_orders_traffickers and Insertion_orders_salespersons each in their own source files, I think you code will work.

Grails error while connecting mysql

i am getting following error while connecting to mysql
i have copied mysql-connector-java-5.1.22-bin.jar to lib folder in my application
| Error 2012-11-26 16:14:16,981 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error executing bootstraps: Error creating bean with name 'transactionManagerPostProcessor': 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.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
Message: Error creating bean with name 'transactionManagerPostProcessor': 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.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
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': 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.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
->> 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': 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.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
->> 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 '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.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
->> 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 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
->> 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 MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
->> 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 SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'
->> 1429 | createConnectionFactory in org.apache.commons.dbcp.BasicDataSource
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1371 | createDataSource in ''
| 1044 | getConnection in ''
| 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: com.mysql.jdbc.Driver
->> 366 | run in java.net.URLClassLoader$1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 355 | run in ''
| 354 | findClass in java.net.URLClassLoader
| 423 | loadClass in java.lang.ClassLoader
| 356 | loadClass in ''
| 1420 | createConnectionFactory in org.apache.commons.dbcp.BasicDataSource
| 1371 | createDataSource in ''
| 1044 | getConnection in ''
| 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
You shouldn't copy the jar file into the lib directory when it's available in a Maven repository - it's better to download it once and cache it instead of having multiple copies, one in each of your projects. In fact the MySQL driver is the example we use in the generated BuildConfig.groovy. Just uncomment it and update the version:
dependencies {
runtime 'mysql:mysql-connector-java:5.1.22'
}
If you do have a jar file that's not in a Maven repo, put it in your lib directory. But Grails doesn't automatically discover it, so you need to run grails compile --refresh-dependencies

Grails war deployment on Tomcat asking for hsql driver instead of mysql

I have a grails app that I am trying to deploy onto Tomcat. I used to develop on hsql and wanted to use mysql for production. But when I build the war by running
grails prod war demo.war
and deploy the created war in the tomcat/webapps directory, I get the following error
INFO: Deploying web application archive demo.war
2011-11-29 17:30:03,193 [Thread-2] INFO cfg.Environment - Hibernate 3.3.1.GA
2011-11-29 17:30:03,224 [Thread-2] INFO cfg.Environment - hibernate.properties not found
2011-11-29 17:30:03,240 [Thread-2] INFO cfg.Environment - Bytecode provider name : javassist
2011-11-29 17:30:03,251 [Thread-2] INFO cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
2011-11-29 17:31:25,451 [Thread-2] ERROR context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: 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.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'org.hsqldb.jdbcDriver' for connect URL 'jdbc:mysql://localhost:3306/demoapp?autoreconnect=true'
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
What's puzzling is that I have removed the hsql dependency completely from the Datasource.groovy file. Here is how my Datasource.groovy looks now.
dataSource {
pooled = true
driver.name = "com.mysql.jdbc.Driver"
username = "root"
password = "root"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop','update'
pooled = true
driver.name = "com.mysql.jdbc.Driver"
url = "jdbc:mysql://localhost/demoapp_dev?autoreconnect=true"
username = "root"
password = ""
}
}
test {
dataSource {
pooled = true
driver.name = "com.mysql.jdbc.Driver"
dbCreate = "update"
url = "jdbc:mysql://localhost/demoapp_test?autoreconnect=true"
username = "root"
password = ""
}
}
production {
dataSource {
pooled = true
driver.name = "com.mysql.jdbc.Driver"
dbCreate = "update"
url = "jdbc:mysql://localhost/demoapp?autoreconnect=true"
username = "root"
password = ""
}
}
}
How do I get around this problem? Any help is appreciated.
Try using driverClassName instead of driver.name to define your DataSource driver.
This happens when you don't have the MySQL driver in your class path don't have the driverClassName, as per schmolly159's answer.
Make sure mysql-connector-java-x.x.xx.jar is in your lib directory or declare it as a dependency in BuildConfig.groovy.