Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Service triggering N+1 queries
void logMessages() {
// Get all the messages from the database
// -> Triggers 1 query
Set<Message> messages = messageDao.findAll();
// Map through the N messages to create the DTO with the author display name
// -> Triggers 1 query to fetch each author so N queries!
message ->
message.getAuthor().getName() + ": " + message.getText()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment