0

I am taking the LazyInitializationException error when because in myController when I read the Lazy collections session is already closed. Is there any way to get it open as long as there is a request? As OpenSessionInView? What would be the best way?

I'm using the version of Spring Boot 1.3.0

2 Answers2

0

You need use the "open session in view" to keep the session open after the end of the transaction.

see OpenSessionInViewFilter or OpenEntityManagerInViewFilter for JPA

imho it's better than extending the scope of the transaction to your controller.

benbenw
  • 723
  • 7
  • 20
0

If you're using a jackson/hibernate combination you can register the jackson-datatype-hibernate module, and tweak the Feature.FORCE_LAZY_LOADING property to your liking. The default is false means that only already fetched properties will be serialized. Changing to true will force initialization of the lazy properties

Master Slave
  • 27,771
  • 4
  • 57
  • 55