Wednesday, 19 October 2011

Grails doing unexpected Hibernate selects when checking if lazy properties are null

So this bug cost me several hours of my precious time. I had to check if a member of a GORM entity is null or not without lazy loading that same entity. Turns out it is not very simple, nor is it intuitive. Doing a simple
if (object.property == null) {..}
triggered a Hibernate load. A working solution is explained here: you have to do
if (object.propertyId == null) {..}

I cannot find this in the documentation but as the docs are huge, I may have very well missed it.

No comments:

Post a Comment