So I kept getting this "failed to lazily initialize a collection of
role" error when working with my relationships, but it didn't happen
everywhere, just in certain cases and it was really bugging me.
So I was reading this blog (http://www.compoundtheory.com/?
action=displayPost&ID=419) and I know why the issue was happening
sometime and not others, even though I might be using the same objects
and relationships (ie. person).
So when I create the person object (myself) and store it in session,
it stores all it's relationships too at that time, but then at the end
of that request, the Hibernate session is closed and thus those
relationships are detached until the next session request (assuming
the next request has them...hence the lazy loading). However, if I
try to access a relationship like person.getOrganization() but at the
time the session was stored, the org information wasn't required, so
it wasn't loaded (ie. lazy loading), then I end up getting this error.
Setting "lazy" to false solved my issue for now, however that isn't
going to be a good long term, scalable solution.
So what I would like to know is if anyone else had experienced this,
and what they did to alleviate it?
I could just store ID's only in session and then get data as needed,
in each handler, but then I'm having to have a ton of "injects" where
I may not need them, just to get the data of something that could be
stored from the get go.
Specifically I'm looking for pros and cons and if anyone has any
really neat tricks up their sleeves to keeping code as slim as
possible but still maximize performance with lazy loading (especially
in a situation where it would be better to just store data in
sessionStorage about the current user, than to always be going back to
the database for basic user information/relationships).
If there is a better group/forum in which to address this, point me in
the right direction and I'll go, but I figured you guys might have
experienced the same thing and have some good ideas/suggestions.
Thanks in advance.