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

Thomas Nilsen
Thomas Nilsen
14,957 Points

Rest API in Spring

The workshop was great.

However, I came across something that is important to be aware of.

If you make a call to /reviews, you get a whopping 22(!!) calls to the DB. This is completely unnecessary, and could easily lead to performance issues.

alt text

This is called the N+1 problem in hibernate

One fix for this, would be to annotate the Course table like so:

@Entity
@BatchSize(size = 10)
public class Course extends BaseEntity {

}

This would essentially reduce the number of queries to N / 10+1

After I add this and make a new request to /reviews, this is the result:

alt text

Down to 4 queries. Much better.