GORM / Hibernate differences between Grails 1.3.9 and Grails 2

19 views
Skip to first unread message

Robert Stroud

unread,
Nov 24, 2016, 11:58:27 AM11/24/16
to Grails Dev Discuss
Hello,

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?

Thanks,

Robert
Reply all
Reply to author
Forward
0 new messages