Grails 2.2.1
My Simple domain:
class Article{
SortedSet<Photo> photoGallery
//helper method
Photo getMainPhoto(){
Photo mainPhoto = photoGallery.find{it.mainPhoto}
return mainPhoto
}
}
The one-to-many photoGallery is fetched lazily
I invoke the getMainPhoto
method from the a .gsp view.
The problem is that sometimes (not always) i get a LazyInitializationException
error when trying to fetch the main photo from the lazy one-to-many photo gallery.
Why this happens occasionally and not each time i invoke that method? Is that normal? And how can i fix that, without making the relationship eagerly fetched?
Thanks