1

I my spring boot application, I have a couple of RestControllers, mainly used by our Web-Frontend.

But there is also a scheduled job, that uses the interface methods of the RestControllers to get and post data.

My problem is, that whenever the scheduled job retrieves an entity with a @OneToMany relationship, these collections are not accessible anymore. I get an error message like

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: MyEntity.myRelationship, could not initialize proxy - no Session

I added this annoation to all my relationships:

    @LazyCollection(LazyCollectionOption.FALSE)

But this is a lot of boiler-plate code and it is easy to forget one of these annotations, which will cause runtime exceptions.

How can I make lazy collections of entities, that my RestControllers return, accessible in my scheduled method?

slartidan
  • 20,403
  • 15
  • 83
  • 131
  • Possible duplicate of [How to resolve LazyInitializationException in Spring Data JPA?](https://stackoverflow.com/questions/26507446/how-to-resolve-lazyinitializationexception-in-spring-data-jpa) – Reza Nasiri Dec 12 '18 at 17:38

0 Answers0