Why grails throwing null pointer exception while accessing hasMany relationship first time?
问题 I have a strange problem. I have two domain classes User and Post with fields: class User { String name static hasMany = [posts: Post] static constraints = { } } and class Post { String content long date = System.getTimeInMillis() static constraints = { } static belongsTo = [user: User] static mapping = { version: 'false' } } and controller code is: class UserController { def addUser = { def user if (User.count() == 0) { user = new User() user.name = "Manish Zedwal" user.save(flush: true) }