Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Raphael Zamora
Raphael Zamora
7,470 Points

How are Reviews saved to the Review Repository?

In the DatabaseLoader class, we add Reviews to a Course like so

Course course = new Course("Java Basics", "https://teamtreehouse.com/library/java-basics");
    course.addReview(new Review(3, "Test review"));
    courses.save(course);

In the Course class, we have the addReview method that adds the review to the Courses private field of Reviews

public class Course extends BaseEntity{
 @OneToMany(mappedBy = "course", cascade = CascadeType.ALL)
  private List<Review> reviews;

  public void addReview(Review review){
    review.setCourse(this);
    reviews.add(review);
  }

At what point are the reviews saved to the Review Repository? We never create an instance of the ReviewRepository and call the save method, yet the Reviews are added to the database. Is this because of Cascading or because of the @OneToMany and @ManyToOne annotations?