0

I have a many to many relationship bewteen Release and Project. The Release entity expresses that relationship like this;

@OneToMany(fetch = FetchType.LAZY, mappedBy = "release")
private List<ProjectRelease> releaseProjects;

Inside a @Transactional method a new Release is created along with its associated projects.

During that transaction execution and after I've called the save method on the ReleaseRepository and ProjectReleaseRepository, I make a call to release.getReleaseProjects() which returns null.

However, If I make a call to projectReleaseRepository.findByReleaseCode(release.code), this would return the acual list of projects that have been associated to the release during the present transaction.

What's causing the release.getReleaseProjects() list to be null during the transaction execution? What's the right way to go here?

Carlos Gonzalez
  • 607
  • 1
  • 5
  • 13
  • Take a look at this question: [Difference between FetchType LAZY and EAGER in Java Persistence API?](https://stackoverflow.com/questions/2990799/difference-between-fetchtype-lazy-and-eager-in-java-persistence-api) – Enfield Li Oct 18 '22 at 23:44
  • I'm calling the release.getReleaseProjects() so that list should be loaed on-demand, I understand that, what I don't understand is why the list is null – Carlos Gonzalez Oct 18 '22 at 23:55

0 Answers0