Consider the domain classes, Project and User defined as follows

and

Note that I've used a List to store the objects on the other side of the many-to-many relationship. Next I create test data in the BootStrap class as follows,

Upon deploying the application, I get the following exception
Caused by: org.springframework.dao.DataIntegrityViolationException: not-null property references a null or transient value: Project._User_projectsBackref; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: Project._User_projectsBackref
This is rather puzzling. The exception suggests an object referencing issue, but it's not clear what this is. Equally baffling is the solution to this problem. The domain classes above use a List to store their many-to-many collaborators. By simply reverting to the default collection type, i.e. a Set, the problem disappears. So for the code above remove line 7 in both classes and the app should deploy without any problems.
I recently came across this JIRA ticket which suggests this is a problem the grails team are aware of.
3 comments:
doh... Grails sometimes make me mad.
Here is a JIRA ticket with the solution (workaround) to the problem:
http://jira.codehaus.org/browse/GRAILS-3783
Post a Comment