0

I have Lazy Loaded OneToMany, ManyToMany and ManyToOne collections in my Spring JPA entities. Whenever I want to load my OneToMany and MantToMany collections into my transaction, I use this trick

school.getStudents().size()

In a similiar fashion, I would like to load my ManyToOne collection (say School->City). How would I eagerly load my City data into my transaction in some 'simple way' similiar to the OneToMany collection show above.

My alternatives right now are

  1. Change the ManyToOne to Eager loading
  2. Write a JPQL query fetching the city while fetching the school data. But this is not very flexible if I have multiple ManyToOne entities and any additional fields involves changing the JPQL query.

Would appreciate any suggestions.

HopeKing
  • 3,317
  • 7
  • 39
  • 62

0 Answers0