I'm using jackson to generate the JSON response.
1.Spring 3.0, configured with ContentNegotiatingViewResolver to server XML and JSON response.
2.Spring MVC, annotation. Most entities have one and more relationship with another entities. For example : parent one-to-many child.
3.Web page, I'm plan to use a existed JQuery grid plugin to present data. The grid can support pagenation, cell editor. It use JSON the data source.
It works well when generating html response. It also can generate XML. But when generating JSON, will throw a exception :
looks like a problem caused by jackson. When jackson try to fetch associated objects, there is no session opened.Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.aaa.bbb.domain.User.roles, no session or session was closed
I searched the internet, found some solutions. But they are not suitable to my case because they are managing the session themself. In my case, I'm using Spring to manage the session.
What can I do? Or is there something wrong with my solution?
Thanks in advance!
for this situation , I can solve it through set the FetchType.Eager. But for those entities which have many associated entities, if i can set all to FetchType.Eager. I think there must arise a performance problem. What can I do?