GORM / Hibernate differences between Grails 1.3.9 and Grails 2

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

GORM / Hibernate differences between Grails 1.3.9 and Grails 2

Robert Stroud

I am porting an old Grails application from Grails 1.3.9 to Grails 2 - currently Grails 2.3.11 - and I have noticed some changes in the behaviour of the GORM / Hibernate persistent object layer that don't appear to be documented in the release notes. I wondered if anyone could explain the rationale for these changes and perhaps suggest a a workaround.

The first issue is that code that worked in Grails 1.3.9 is now failing with "object references a transient object instance" - this suggests some change in the underlying semantics of how object dependencies work. Can anyone shed any light on why my code worked in Grails 1.3.9 but fails with Grails 2.3.11? Is there an easy way to fix this problem - for example, by tightening up the object dependency declarations - or am I going to have to add save() statements everywhere that the code creates a transient object?

The second issue is that it is no longer possible to set the id for a domain object via its constructor in a unit test - the id is always set to null. However, you can set the id property separately. This has broken a number of unit tests that depended on setting dummy id values - I've had to replace "d = new Domain(id: x)" with "d = new Domain(); d.id = x". I can understand why setting the id value might be deprecated but it seems a bit inconsistent to allow the id to be set via a property assignment if it can't be set via the constructor. Again, can anyone shed any light on why the semantics were changed in this way?



You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/92e10063-7f49-4d23-8186-4d6122f69942%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.