No signature of method addTo* is applicable

No signature of method addTo* is applicable

Last night, I started getting an exception in one of my pet projects, created with Grails:

No signature of method: package.Parent.addToChildren() is applicable for argument types: (package.Child) values: [package.Child : null]
Possible solutions: getChildren(). Stacktrace follows:
groovy.lang.MissingMethodException: No signature of method: package.Parent.addToChildren() is applicable for argument types: (package.Child) values: [package.Child : null]

I searched for the problem, read dozens of different hints regarding proper general ORM one-to-many setups, GORM-specific hasMany/belongsTo relationships, cascading, saving before adding, etc. All were different problems leading to the same exception.

My problem, however, was far more trivial. Here’s the code that made me want to tear my hair out.

class Parent {
	static hasMany = {
		children: Child
	}
}

Do you spot the mistake?

I used curly braces for the hasMany relationship. Groovy doesn’t complain at all, as it’s valid syntax. But to make GORM work the expected way, it should be square brackets:

class Parent {
	static hasMany = [
		children: Child
	]
}

I’ve lost two hours of my life to this one.

Enabling Tomcat NIO Connector with Grails 2.0

Next Article

Enabling Tomcat NIO Connector with Grails 2.0

At dozens of different sources it says that you need to put grails.tomcat.nio=true into your Config.groovy file - apparently that's not true, at least it wasn't working for me.
  1. Thanks a looot man! Never figured that out… if it was not because of you I would have lost like many more hours of my life too

  2. Thank you for this post!