aistomin / andys.backend

Andy's Website. Backend.
0 stars 0 forks source link

Fetch Video.sheets and Video.lyrics lazily #414

Closed aistomin closed 4 months ago

aistomin commented 5 months ago

Get rid of FetchType.EAGER in the code like following:

/**
* Music sheets that belong to the video.
*/
@OneToMany(fetch = FetchType.EAGER)
private Set<MusicSheet> sheets = new HashSet<>();
aistomin commented 4 months ago

Fixed. In order to achieve the desired behaviour, I had to explicitly tell Hibernate how to fetch the dependent collections: I used @Query annotations for getters.

aistomin commented 4 months ago

Actually, it was not necessary. The problem was not the code itself, but the test. You obviously need a session to load those entities lazily. When I marked test as @Transactional everything works without any additional modifications of the source code, I just had to remove this fetch = FetchType.EAGER configuration.