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?