I have the following two simple models creating a bidirectional one-to-many relationship in a Grails 2.4.3 application:
class Player {
String firstName
String lastName
String position
static belongsTo = [team: Team]
}
class Team {
String name
List players = new ArrayList()
static hasMany = [players: Player]
static mapping= {
players cascade:"all-delete-orphan"
}
}
I would like to be able to save and update teams and their associated players via nested JSON, like so:
{
name : "team A",
players : [
{
firstName : "john",
lastName :"doe",
position : "center"
}
]
}
My TeamController save action looks like this:
def save() {
def team = new Team(request.JSON)
team.save()
respond team
}
When I make a request with that JSON, I get an error:
curl -X POST -d '{name:"team a",players:[{firstName:"john",lastName:"doe",position:"center"}]}' http://localhost:8080/team-test/team/save.json --header "Content-Type:application/json"
Produces this output in console:
| Error 2014-11-14 10:32:26,111 [http-bio-8080-exec-6] ERROR errors.GrailsExceptionResolver - NullPointerException occurred when processing request: [POST] /team-test/team/save.json
Stacktrace follows:
Message: null
Line | Method
->> 8 | save in team.test.TeamController$$EOvbjH0K
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 198 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Because that's a rather vague message, I put a try/catch around the team.save() call in the TeamController and print out the stack trace:
def save() {
def team = new Team(request.JSON)
try {
team.save()
}
catch(Exception e)
{
e.printStackTrace()
}
respond team
}
Error java.lang.NullPointerException
| Error at org.hibernate.engine.spi.BatchFetchQueue.removeBatchLoadableEntityKey(BatchFetchQueue.java:163)
| Error at org.hibernate.engine.internal.StatefulPersistenceContext.addEntity(StatefulPersistenceContext.java:388)
| Error at org.hibernate.engine.internal.StatefulPersistenceContext.addEntity(StatefulPersistenceContext.java:461)
| Error at org.hibernate.action.internal.AbstractEntityInsertAction.makeEntityManaged(AbstractEntityInsertAction.java:143)
| Error at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:201)
| Error at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:179)
| Error at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:214)
| Error at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:324)
| Error at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:288)
| Error at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:194)
| Error at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
| Error at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
| Error at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
| Error at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:114)
| Error at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
| Error at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:684)
| Error at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:676)
| Error at org.hibernate.engine.spi.CascadingActions$5.cascade(CascadingActions.java:235)
| Error at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:350)
| Error at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:293)
| Error at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:161)
| Error at org.hibernate.engine.internal.Cascade.cascadeCollectionElements(Cascade.java:379)
| Error at org.hibernate.engine.internal.Cascade.cascadeCollection(Cascade.java:319)
| Error at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:296)
| Error at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:161)
| Error at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:118)
| Error at org.hibernate.event.internal.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:460)
| Error at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:294)
| Error at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:194)
| Error at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
| Error at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:209)
| Error at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:194)
| Error at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:114)
| Error at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
| Error at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:684)
| Error at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:676)
| Error at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:671)
| Error at org.codehaus.groovy.grails.orm.hibernate.metaclass.SavePersistentMethod$1.doInHibernate(SavePersistentMethod.java:58)
| Error at org.codehaus.groovy.grails.orm.hibernate.GrailsHibernateTemplate.doExecute(GrailsHibernateTemplate.java:179)
| Error at org.codehaus.groovy.grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:123)
| Error at org.codehaus.groovy.grails.orm.hibernate.metaclass.SavePersistentMethod.performSave(SavePersistentMethod.java:56)
| Error at org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractSavePersistentMethod.doInvokeInternal(AbstractSavePersistentMethod.java:215)
| Error at org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractDynamicPersistentMethod.invoke(AbstractDynamicPersistentMethod.java:68)
| Error at org.codehaus.groovy.grails.orm.hibernate.HibernateGormInstanceApi.save(HibernateGormInstanceApi.groovy:156)
| Error at team.test.Team$$EOvbjH0K.save(Team.groovy)
| Error at team.test.Team$$DOvbjH0K.save(Unknown Source)
| Error at team.test.Team.save(Team.groovy)
| Error at team.test.Team$save.call(Unknown Source)
| Error at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
| Error at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
| Error at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
| Error at team.test.TeamController$$EOvbkj0y.save(TeamController.groovy:9)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| Error at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
| Error at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
| Error at java.lang.reflect.Method.invoke(Method.java:606)
| Error at org.springsource.loaded.ri.ReloadedTypeInvoker$2.invoke(ReloadedTypeInvoker.java:122)
| Error at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1299)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.MixedGrailsControllerHelper.invoke(MixedGrailsControllerHelper.java:154)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleAction(AbstractGrailsControllerHelper.java:375)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.executeAction(AbstractGrailsControllerHelper.java:252)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleURI(AbstractGrailsControllerHelper.java:205)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.AbstractGrailsControllerHelper.handleURI(AbstractGrailsControllerHelper.java:126)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.SimpleGrailsController.handleRequest(SimpleGrailsController.java:72)
| Error at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:50)
| Error at org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet.doDispatch(GrailsDispatcherServlet.java:347)
| Error at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
| Error at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
| Error at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
| Error at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
| Error at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
| Error at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:198)
| Error at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
| Error at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
| Error at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
| Error at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)
| Error at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)
| Error at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
| Error at org.codehaus.groovy.grails.web.mapping.UrlMappingUtils.forwardRequestForUrlMappingInfo(UrlMappingUtils.java:178)
| Error at org.codehaus.groovy.grails.web.mapping.UrlMappingUtils.forwardRequestForUrlMappingInfo(UrlMappingUtils.java:144)
| Error at org.codehaus.groovy.grails.web.mapping.UrlMappingUtils.forwardRequestForUrlMappingInfo(UrlMappingUtils.java:135)
| Error at org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter.doFilterInternal(UrlMappingsFilter.java:216)
| Error at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:69)
| Error at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
| Error at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
| Error at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
| Error at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
| Error at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
| Error at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
| Error at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
| Error at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
| Error at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
| Error at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
| Error at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
| Error at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
| Error at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
| Error at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
| Error at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
| Error at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
| Error at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
| Error at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
| Error at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
| Error at java.lang.Thread.run(Thread.java:745)
For further investigation, I put some logging in the controller action to see what's going on within the object:
def save() {
JSON.use('deep')
def team = new Team(request.JSON)
println "errors? " + team.getErrors()
println "team: " + team.toString()
println ((team as JSON).toString())
respond team
}
which produces the following output:
errors? grails.validation.ValidationErrors: 0 errors
team: team.test.Team : (unsaved)
{
"class":"team.test.Team",
"id":null,
"name":"team a",
"players":[
{
"class":"team.test.Player",
"id":null,
"firstName":"john",
"lastName":"doe",
"position":"center",
"team":null
}
]
}
Is there something wrong with my JSON? Why do I get this error? Is it because the team reference is null in the player object? Why is the team reference null in the player object?
Out of curiosity, I removed the belongsTo property from the Player class, and things work as expected...
{"class":"team.test.Team","id":2,"name":"team a","players":[{"class":"team.test.Player","id":2}]}
Why does it not work in the bidirectional case? What are the different implications of bidirectional and unidirectional in terms of table relationships, data binding, etc? I understand the different cascade strategies when using belongsTo or not in a one-to-many relationship, but both should cascade saves I thought.
I know I'm asking many questions. I need help making this work but would also like to understand what is happening in principle. Help is much appreciated.
edit:
per #th3morg's suggestion I attempted manually building out the Team and Player models and associating them via Team.addToPlayers().
def save() {
JSON.use('deep')
def teamData = request.JSON
def team = new Team()
team.name = teamData.name
teamData.players.each { playerData ->
def player = new Player(playerData)
team.addToPlayers(player)
}
team.save()
println ((team as JSON).toString())
respond team
}
produces:
{"class":"team.test.Team","id":3,"name":"team a","players":[{"class":"team.test.Player","id":3,"firstName":"john","lastName":"doe","position":"center","team":{"_ref":"../..","class":"team.test.Team"}}]}
This appears to work, but it is verbose and fragile. Is there no way to achieve the same result through automatic binding or through some other conventional magic?
I think in your case, the reason is straightforward - you need to explicitly call team.addToPlayers(player) before you save. I'm guessing that instantiating a team with the JSON constructor is equivalent to the Map constructor, which is basically equivalent to doing the following:
def team = new Team()
team.players = [new Player(), new Player()]
team.save()
i.e. setting the players properly directly, rather than calling addToPlayers.
If you run this in a test app, you will get exactly the same exception as you received in your version. This is because (as you've recognized), each Player does not have a back-reference to the Team set (which is what team.addToPlayers()) does. This (strangely) still saves the player object because the Hibernate session flushes when the controller finishes, saving any unsaved instances.
I'd be surprised if removing belongsTo property from the Player class actually fixes the issue - did it actually persist the TeamPlayers relationship? Or did it just look like it worked because you were responding with a JSON object where you had effectively manually set the players property?
I realize this is over a year old now, but the reason why I'm commenting is to leave a note for others : there is a (possibly related) known Grails bug which throws the same exception with multiple cascading relationships (e.g. A -> hasMany -> B hasMany -> C) where a child/grandchild has a beforeInsert() or beforeUpdate() method. This may be fixed in Grails 3.x but looks like it will not be fixed in 2.x. - see here and here.
You may be able to fix this with a beforeSave() function within your Team domain where you iterate over the players and save each player. This should avoid hibernate trying to save the transient player objects and also prevent you from having to code it yourself in the controller, which is a bit odd feeling.
Also, using GSON, you might be able to avoid any of the addTo associations hibernate would want.
https://github.com/robfletcher/grails-gson#readme
Related
I am trying to connect RunDeck with MySQL server but seeing below errors:-
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.java:524)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.java:470)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applyIndexes(AbstractSchemaMigrator.java:327)
at org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl.performTablesMigration(GroupedSchemaMigratorImpl.java:84)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:203)
at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:110)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:176)
at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:65)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:478)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:422)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:711)
at org.grails.orm.hibernate.cfg.HibernateMappingContextConfiguration.buildSessionFactory(HibernateMappingContextConfiguration.java:276)
at org.grails.orm.hibernate.connections.HibernateConnectionSourceFactory.create(HibernateConnectionSourceFactory.java:86)
at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:39)
at org.grails.orm.hibernate.connections.AbstractHibernateConnectionSourceFactory.create(AbstractHibernateConnectionSourceFactory.java:23)
at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:64)
at org.grails.datastore.mapping.core.connections.AbstractConnectionSourceFactory.create(AbstractConnectionSourceFactory.java:52)
at org.grails.datastore.mapping.core.connections.ConnectionSourcesInitializer.create(ConnectionSourcesInitializer.groovy:24)
at org.grails.orm.hibernate.HibernateDatastore.<init>(HibernateDatastore.java:201)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:271)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1201)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1103)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:648)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:145)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1201)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1103)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:931)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:808)
at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:564)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:432)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:395)
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:206)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1267)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:467)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1181)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1075)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:225)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:703)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:528)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at grails.boot.GrailsApp.run(GrailsApp.groovy:84)
at grails.boot.GrailsApp.run(GrailsApp.groovy:393)
at grails.boot.GrailsApp.run(GrailsApp.groovy:380)
at grails.boot.GrailsApp$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136)
at rundeckapp.Application.main(Application.groovy:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.WarLauncher.main(WarLauncher.java:59)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: INDEX command denied to user 'rundeck'#'10.0.0.8' for table 'base_report'
Here is my rundeck-config.properties file
#loglevel.default is the default log level for jobs: ERROR,WARN,INFO,VERBOSE,DEBUG
loglevel.default=INFO
rdeck.base=/var/lib/rundeck
#rss.enabled if set to true enables RSS feeds that are public (non-authenticated)
rss.enabled=false
# change hostname here
grails.serverURL=http://10.0.0.8:4440
dataSource.dbCreate = update
dataSource.url = jdbc:mysql://my-dev.************.us-east-1.rds.amazonaws.com:3306/rundeck?autoReconnect=true&useSSL=false
dataSource.username = rundeck
dataSource.password = ***************
dataSource.driverClassName=com.mysql.jdbc.Driver
rundeck.log4j.config.file = /etc/rundeck/log4j.properties
I have copied JDBC driver as well to /var/lib/rundeck/libext
[rundeck#mysever]$ pwd && ls -ld mysql-connector-java-5.1.46
/var/lib/rundeck/libext
drwxr-xr-x 3 rundeck rundeck 4096 Feb 26 13:28 mysql-connector-java-5.1.46
I have followed instructions here:
http://rundeck.org/2.10.6/administration/setting-up-an-rdb-datasource.html#setup-mysql
Even though I can see table structure in my RDS but there is no entry in any of the table
mysql> show tables;
+----------------------------+
| Tables_in_rundeck |
+----------------------------+
| auth_token |
| base_report |
| execution |
| job_file_record |
| log_file_storage_request |
| node_filter |
| notification |
| orchestrator |
| plugin_meta |
| project |
| rdoption |
| rdoption_values |
| rduser |
| referenced_execution |
| report_filter |
| scheduled_execution |
| scheduled_execution_filter |
| storage |
| workflow |
| workflow_step |
| workflow_workflow_step |
+----------------------------+
INDEX command denied to user 'rundeck'#'10.0.0.8' for table 'base_report'
You have a permissions issue that is causing the Schema Migration to fail. You should have run:
GRANT ALL ON rundeck.* to rundeck;
You can check the current permissions with:
SHOW GRANTS FOR rundeck;
I am working remotely for a firm based in India and I am connecting to the company network via VPN for daily work.
I am currently implementing a project in grails 2.2.4 which is on my local system / computer. The grails project in GGTS runs fine when connected to the local db on my machine.
But, when I am trying to connect to a database which is hosted in a server on my Company's network from my project's development environment, I am getting a lot of connection errors, all of it from MySQL.
I have configured my DataSource.groovy as below:
dataSource {
pooled = true
driverClassName="com.mysql.jdbc.Driver"
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
username = <username>
password = <password>
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache=true
cache.provider_class='net.sf.ehcache.hibernate.EhCacheProvider'
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
environments {
development {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://<remoteIP-on company network>:3306/<DB_Name>"
properties{
initialSize="50"
maxActive="100"
minIdle="50"
maxIdle="75"
maxWait="30000"
timeBetweenEvictionRunsMillis="5000"
minEvictableIdleTimeMillis="60000"
testWhileIdle="true"
testOnBorrow="true"
testOnReturn="true"
poolPreparedStatements="true"
maxOpenPreparedStatements="100"
validationQuery="SELECT 1 FROM DUAL"
connectionInitSqls="SELECT 1 FROM DUAL"
logAbandoned="true"
}
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://<remoteIP-on company network>:3306/<DB_Name>"
driverClassName="com.mysql.jdbc.Driver"
username = <username>
password = <password>
}
}
production {
dataSource {
dbCreate = "update"
jndiName = "java:comp/env/<JNDIName>"
properties {
maxActive = 50
maxIdle = 25
minIdle = 5
initialSize = 5
minEvictableIdleTimeMillis = 60000
timeBetweenEvictionRunsMillis = 60000
maxWait = 10000
}
}
}
}
My BuildConfig.groovy has the following dependencies set:
dependencies {
runtime 'mysql:mysql-connector-java:5.1.40'
}
and I have the mysql-connector-java-5.1.40-bin.jar file added to the build path and the /lib/ folder .
On the remote DB, by connecting to it through HeidiSQL client on my machine, I have run the following query based on my research on the same topic of discussion.
GRANT ALL PRIVILEGES ON <DB_Name>.* TO <username>#'%' IDENTIFIED BY <password>;
FLUSH PRIVILEGES;
When I ping to the remote server from the command prompt, that too works fine.
ping <Remote Server IP>
Pinging <Remote Server IP> with 32 bytes of data:
Reply from <Remote Server IP>: bytes=32 time=261ms TTL=61
Reply from <Remote Server IP>: bytes=32 time=261ms TTL=61
Reply from <Remote Server IP>: bytes=32 time=257ms TTL=61
Reply from <Remote Server IP>: bytes=32 time=257ms TTL=61
Ping statistics for <Remote Server IP>:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 257ms, Maximum = 261ms, Average = 259ms
Now, when I run the application using GGTS Run As -> Grails Command (run-app) I get the following error:
| Error 2016-12-13 18:36:05,400 [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': Cannot resolve reference to bean 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 PoolableConnectionFactory (Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
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 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 PoolableConnectionFactory (Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
Line | Method
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | 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 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 PoolableConnectionFactory (Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 PoolableConnectionFactory (Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 PoolableConnectionFactory (Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
Caused by MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
->> 334 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
Caused by SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
->> 1549 | createPoolableConnectionFactory in org.apache.commons.dbcp.BasicDataSource
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1388 | createDataSource in ''
| 1044 | getConnection in ''
| 334 | innerRun in java.util.concurrent.FutureTask$Sync
| 166 | run . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run in java.lang.Thread
Caused by CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
->> 409 | handleNewInstance in com.mysql.jdbc.Util
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1118 | createCommunicationsException in com.mysql.jdbc.SQLError
| 343 | <init> . in com.mysql.jdbc.MysqlIO
| 2308 | connectOneTryOnly in com.mysql.jdbc.ConnectionImpl
| 2122 | createNewIO in ''
| 774 | <init> in ''
| 49 | <init> . in com.mysql.jdbc.JDBC4Connection
| 409 | handleNewInstance in com.mysql.jdbc.Util
| 375 | getInstance in com.mysql.jdbc.ConnectionImpl
| 289 | connect in com.mysql.jdbc.NonRegisteringDriver
| 38 | createConnection in org.apache.commons.dbcp.DriverConnectionFactory
| 582 | makeObject in org.apache.commons.dbcp.PoolableConnectionFactory
| 1556 | validateConnectionFactory in org.apache.commons.dbcp.BasicDataSource
| 1545 | createPoolableConnectionFactory in ''
| 1388 | createDataSource in ''
| 1044 | getConnection in ''
| 334 | innerRun in java.util.concurrent.FutureTask$Sync
| 166 | run in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run . . . in java.lang.Thread
Caused by ConnectException: Connection refused: connect
->> 79 | socketConnect in java.net.DualStackPlainSocketImpl
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 339 | doConnect in java.net.AbstractPlainSocketImpl
| 200 | connectToAddress in ''
| 182 | connect in ''
| 172 | connect . in java.net.PlainSocketImpl
| 392 | connect in java.net.SocksSocketImpl
| 579 | connect . in java.net.Socket
| 528 | connect in ''
| 425 | <init> . in ''
| 241 | <init> in ''
| 256 | connect . in com.mysql.jdbc.StandardSocketFactory
| 292 | <init> in com.mysql.jdbc.MysqlIO
| 2308 | connectOneTryOnly in com.mysql.jdbc.ConnectionImpl
| 2122 | createNewIO in ''
| 774 | <init> . in ''
| 49 | <init> in com.mysql.jdbc.JDBC4Connection
| 409 | handleNewInstance in com.mysql.jdbc.Util
| 375 | getInstance in com.mysql.jdbc.ConnectionImpl
| 289 | connect . in com.mysql.jdbc.NonRegisteringDriver
| 38 | createConnection in org.apache.commons.dbcp.DriverConnectionFactory
| 582 | makeObject in org.apache.commons.dbcp.PoolableConnectionFactory
| 1556 | validateConnectionFactory in org.apache.commons.dbcp.BasicDataSource
| 1545 | createPoolableConnectionFactory in ''
| 1388 | createDataSource in ''
| 1044 | getConnection in ''
| 334 | innerRun in java.util.concurrent.FutureTask$Sync
| 166 | run . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run in java.lang.Thread
I have tried all the available solutions from stack-overflow and other websites.
Till now I've been following the solutions available on
http://docs.grails.org/latest/guide/single.html#dataSource
Access MySQL server from Grails
and a few other links which I am not able to post here due to less reputation on stack-overflow.
I have done exactly the same that has been asked to be done on all of the solutions available in the above mentioned links. Still I am having the same error. I am not sure what I am missing out on. Not even sure if this is caused due to the VPN connection or something.
Please help me.
The issue got resolved finally.
I checked the MySQL conf file my.cnf in the server location ./etc/mysql/ . In the file my.cnf, under [mysqld] section, bind-address is set to 127.0.0.1. Instead of skip-networking being set to True, the default is now to listen only on localhost for all mysql ubuntu installations in order to avoid other servers connecting to mySQL.
Hence I commented out the line, setting bind-address=127.0.0.1 in the file my.cnf in ./etc/mysql/ folder and restarted the mysql and it worked like a charm!
Sometime when we have layer e.g docker, firewell, or proxy then these type of error comes which are harder to troubleshoot. I have faced similary type of error. I just solved this issue by bind the server with '0.0.0.0' instead of 'localhost' or '127.0.0.1'. by using this. etc/host will expose the server binding to all interfaces. and then i checked that the IP for localhost by using 'ifconfig' command. then used that IP to my internal archtecture docker application. thats works fine.
I'm using jboss5.1 with spring as the system's architecture. The version of mysql is 5.6.12, and the version of jdk is 1.7.
Scenario : Because I need update the record which the system inserted into the DB no long before,
I try to get the id of the record while executing inserting record.
I used GeneratedKeyHolder(class in spring) to get the auto id . The source is as below :
KeyHolder keyHolder = new GeneratedKeyHolder();
jdbcTemplate.update(new PreparedStatementCreator()
{
public PreparedStatement createPreparedStatement(Connection con) throws SQLException
{
PreparedStatement ps = con.prepareStatement(sql, new String[] { "id" });
ps.setString(1, record.getCmdName());
ps.setTimestamp(6, new Timestamp(System.currentTimeMillis()));
return ps;
}
}, keyHolder);
return keyHolder.getKey().intValue();
In the most environments, the code work well , but in one environment it throws exception as below. It's so surprising , and we failed to reproduce the exception in our testing environment.
INFO | jvm 1 | 2013/09/24 11:03:47 | org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL []; SQL state [null]; error code [0]; Connection is not associated with a managed connection.org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5#42d0cb88; nested exception is java.sql.SQLException: Connection is not associated with a managed connection.org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5#42d0cb88
INFO | jvm 1 | 2013/09/24 11:03:47 | Caused by:
INFO | jvm 1 | 2013/09/24 11:03:47 | java.sql.SQLException: Connection is not associated with a managed connection.org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5#42d0cb88
INFO | jvm 1 | 2013/09/24 11:03:47 | at org.jboss.resource.adapter.jdbc.WrappedConnection.lock(WrappedConnection.java:81)
INFO | jvm 1 | 2013/09/24 11:03:47 | at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:345)
INFO | jvm 1 | 2013/09/24 11:03:47 | at RecordDao$1.createPreparedStatement(RecordDao.java:60)
INFO | jvm 1 | 2013/09/24 11:03:47 | at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:532)
INFO | jvm 1 | 2013/09/24 11:03:47 | at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:771)
INFO | jvm 1 | 2013/09/24 11:03:47 | at RecordDao.insertGongdan(RecordDao.java:56)
INFO | jvm 1 | 2013/09/24 11:03:47 |
INFO | jvm 1 | 2013/09/24 11:03:47 | at java.lang.Thread.run(Thread.java:722)
INFO | jvm 1 | 2013/09/24 11:03:47 | 11:03:47,543 INFO [TL1ServerSession] TL1ServerSession send!
INFO | jvm 1 | 2013/09/24 11:03:47 | 11:03:47,543 INFO [TL1ServerSession] Send TL1 Message:
INFO | jvm 1 | 2013/09/24 11:03:47 |
You get following error message:
Connection is not associated with a managed connection.org.jboss.resource.adapter.jdbc.jdk5.WrappedConnectionJDK5
and you used jdk 1.7. But it not occured this problem.
I start looking in net this problem and find this topic. WhatDoesTheMessageDoYourOwnHousekeepingMean explain the closing a connection what is mean for you.
I think you need to adjust the transaction timeout.#Ellie Fabrero say: Some of the query may take long so the timeout is reach and hibernate throws an exception.
It seems that you "conn" object was not initialized so there is not a valid connection to execute the statement.
I was just getting this error and it looks like it has to do with executing a query when you don't have a valid connection object. In my case, I was looping through a list and calling an insert on each element of the list, but my method was written in a way that cleaned up the connection before the second element was called, thus the error.
I'd imagine the other case is as mentioned above, where the connection object isn't initialized at all.
I had the same problem with this weird message called 'Uncategorized Sql Exception'.
In my case there were some corrupted data in the table that I was doing the select query. It was the reason we can't reproduce in other environment, including mirrored databases.
After cleaning the database table, this issue was solved.
I have an Amazon ec2 mysql database which I connected in my local machine. I have created a database in it named locker.
And I uncommented the line in BuildConfig.groovy to add mysql connector.
Here is my DataSource.groovy file :
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://localhost/locker?useUnicode=yes&characterEncoding=UTF-8"
username = "anto"
password = "****"
}
hibernate {
show_sql = true
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}
}
But when I tried to run my grails app I get an big error like this :
Error 2012-07-05 18:54:53,533 [pool-5-thread-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 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 PoolableConnectionFactory (Access denied for user 'anto'#'localhost' (using password: YES))
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 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 PoolableConnectionFactory (Access denied for user 'anto'#'localhost' (using password: YES))
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 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 PoolableConnectionFactory (Access denied for user 'anto'#'localhost' (using password: YES))
->> 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 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 PoolableConnectionFactory (Access denied for user 'anto'#'localhost' (using password: YES))
->> 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 'lobHandlerDetector': 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 PoolableConnectionFactory (Access denied for user 'anto'#'localhost' (using password: YES))
->> 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 create PoolableConnectionFactory (Access denied for user 'anto'#'localhost' (using password: YES))
->> 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 create PoolableConnectionFactory (Access denied for user 'anto'#'localhost' (using password: YES))
->> 1549 | createPoolableConnectionFactory in org.apache.commons.dbcp.BasicDataSource
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1388 | 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 SQLException: Access denied for user 'anto'#'localhost' (using password: YES)
->> 1073 | createSQLException in com.mysql.jdbc.SQLError
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 3597 | checkErrorPacket in com.mysql.jdbc.MysqlIO
| 3529 | checkErrorPacket in ''
| 935 | checkErrorPacket in ''
| 4101 | secureAuth411 in ''
| 1300 | doHandshake in ''
| 2337 | coreConnect in com.mysql.jdbc.ConnectionImpl
| 2370 | connectOneTryOnly in ''
| 2154 | createNewIO in ''
| 792 | <init> in ''
| 47 | <init> . in com.mysql.jdbc.JDBC4Connection
| 411 | handleNewInstance in com.mysql.jdbc.Util
| 381 | getInstance in com.mysql.jdbc.ConnectionImpl
| 305 | connect in com.mysql.jdbc.NonRegisteringDriver
| 38 | createConnection in org.apache.commons.dbcp.DriverConnectionFactory
| 582 | makeObject in org.apache.commons.dbcp.PoolableConnectionFactory
| 1556 | validateConnectionFactory in org.apache.commons.dbcp.BasicDataSource
| 1545 | createPoolableConnectionFactory in ''
| 1388 | 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
| Error 2012-07-05 18:54:53,630 [pool-5-thread-1] ERROR [localhost].[/locker] - Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
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 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 PoolableConnectionFactory (Access denied for user 'anto'#'localhost' (using password: YES))
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 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 PoolableConnectionFactory (Access denied for user 'anto'#'localhost' (using password: YES))
->> 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 'lobHandlerDetector' while setting bean property 'lobHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lobHandlerDetector': 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 PoolableConnectionFactory (Access denied for user 'anto'#'localhost' (using password: YES))
->> 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 'lobHandlerDetector': 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 PoolableConnectionFactory (Access denied for user 'anto'#'localhost' (using password: YES))
->> 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 create PoolableConnectionFactory (Access denied for user 'anto'#'localhost' (using password: YES))
->> 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 create PoolableConnectionFactory (Access denied for user 'anto'#'localhost' (using password: YES))
->> 1549 | createPoolableConnectionFactory in org.apache.commons.dbcp.BasicDataSource
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1388 | 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 SQLException: Access denied for user 'anto'#'localhost' (using password: YES)
->> 1073 | createSQLException in com.mysql.jdbc.SQLError
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 3597 | checkErrorPacket in com.mysql.jdbc.MysqlIO
| 3529 | checkErrorPacket in ''
| 935 | checkErrorPacket in ''
| 4101 | secureAuth411 in ''
| 1300 | doHandshake in ''
| 2337 | coreConnect in com.mysql.jdbc.ConnectionImpl
| 2370 | connectOneTryOnly in ''
| 2154 | createNewIO in ''
| 792 | <init> in ''
| 47 | <init> . in com.mysql.jdbc.JDBC4Connection
| 411 | handleNewInstance in com.mysql.jdbc.Util
| 381 | getInstance in com.mysql.jdbc.ConnectionImpl
| 305 | connect in com.mysql.jdbc.NonRegisteringDriver
| 38 | createConnection in org.apache.commons.dbcp.DriverConnectionFactory
| 582 | makeObject in org.apache.commons.dbcp.PoolableConnectionFactory
| 1556 | validateConnectionFactory in org.apache.commons.dbcp.BasicDataSource
| 1545 | createPoolableConnectionFactory in ''
| 1388 | 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
| Error 2012-07-05 18:54:53,655 [pool-5-thread-1] ERROR core.StandardContext - Error listenerStart
| Error 2012-07-05 18:54:53,671 [pool-5-thread-1] ERROR core.StandardContext - Context [/locker] startup failed due to previous errors
I'm very new to grails. What went wrong? Can anyone help me?
Thanks in advance.
It looks like the username and password you are using are not valid:
Access denied for user 'anto'#'localhost' (using password: YES)
This isn't a Grails problem, it's a general permissions problem.
Check out this question. It discusses configuring MySQL to allow remote connections and JDBC. You may need to configure MySQL to allow remote connections because the JDBC drive uses TCP/IP sockets to connect to the database regardless of where the database server is running and where the JDBC client is running.
Well, there might be two reasons(or more) of that problem. One is the permission reason, which you should give to your specific user.
Also, I have noticed that in your DataSource.groovy, the url is set to be:
url = "jdbc:mysql://localhost/locker?useUnicode=yes&characterEncoding=UTF-8"
Just to notice, you might forget to add your mysql port in the url, which would lead to the same problem. The way I did is like:
url = "jdbc:mysql://localhost/locker:1234?useUnicode=yes&characterEncoding=UTF-8"
I have mysql table named anto2. Which has only one column name of varchar 100. I tried to map this table in grails domain class :
class Anto {
String grailsName
static constraints = {
}
static mapping = {
table 'anto2'
grailsName column: 'name'
}
}
After I did run-app I can see my table have been added with two more columns :
+---------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| name | varchar(100) | YES | | NULL | |
| id | bigint(20) | NO | | NULL | |
| version | bigint(20) | NO | | NULL | |
+---------+--------------+------+-----+---------+-------+
I generated static view and controller for this Domain class and when I tried to save it , I get an error in my save() method (which is generated using generate-all command). The error is as follows :
2012-07-09 23:05:26,391 [http-bio-8080-exec-2] ERROR errors.GrailsExceptionResolver - SQLException occurred when processing request: [POST] /mysql/anto/save - parameters:
create: Create
Field 'id' doesn't have a default value. Stacktrace follows:
Message: Field 'id' doesn't have a default value
Line | Method
->> 1073 | createSQLException in com.mysql.jdbc.SQLError
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 3597 | checkErrorPacket in com.mysql.jdbc.MysqlIO
| 3529 | checkErrorPacket . in ''
| 1990 | sendCommand in ''
| 2151 | sqlQueryDirect . . in ''
| 2625 | execSQL in com.mysql.jdbc.ConnectionImpl
| 2119 | executeInternal . in com.mysql.jdbc.PreparedStatement
| 2415 | executeUpdate in ''
| 2333 | executeUpdate . . in ''
| 2318 | executeUpdate in ''
| 105 | executeUpdate . . in org.apache.commons.dbcp.DelegatingPreparedStatement
| 25 | save in mnm.AntoController
| 1110 | runWorker . . . . in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . . . . . in java.lang.Thread
Why does this happen? Where I went wrong?
If you don't specify your kind of id generator, GORM will use the native strategy of your database.If you're using mysql as db, it will create your ids using IDENTITY strategy to generate them. This strategy requires to have an auto increment on your id column.
Although I think defining a strategy is better. You can use the SEQUENCE strategy:
id column:'id_anto2', generator:'sequence', params:[sequence:'tab_anto2_seq']
and then create a sequence with that same name in your database (so you don't have to use the one Hibernate creates for you automatically). It's very easy and works like a charm.
Also, to discard the version field, insert version false in your mapping block. So, it would be like:
static mapping = {
table 'anto2'
id column: 'id_anto2', generator: 'sequence', params: [sequence:'tab_anto2_seq']
grailsName column: 'name'
version false
}
It looks like you are missing id mapping. Try adding an id reference to your static mapping closure. Also, if this is an existing database you might want to set the version to false or grails might try to alter the table with a version column, depending on how you have datasource.groovy set up.
table 'anto2'
version false
id column:'anto2_ID'
grailsName column: 'name'