Tuesday, 8 May 2012

Before saving your entities...

Grails uses the ActiveRecord paradigm borrowed from Rails, so one can do something like:
new UserRole(user: user, role: role).save(flush: false, insert: true)  
Unlike Rails though, Grails uses Hibernate in the background, and unfortunately you can get yourself into a heap of Hibernate nastyness (like what happened to me) if your User object above isn't a persistent entity (ie. has no ID assigned to it). I found that the hard way after debugging deep into the Hibernate code yesterday =(

No comments:

Post a Comment