Urgent.News

What's breaking now, across thousands of outlets.

Tech

Hibernate Under the Hood. Part 7: Performance and Common Pitfalls

Performance issues are rarely the fault of Hibernate itself; more often, they are caused by its misuse. The key to success is identifying these issues before they manifest in production. How to Find Problems Before Production Performance issues are barely visible on a small test database with a single user, but they manifest catastrophically on real data under load. Therefore, you must start by…

Performance issues in Hibernate are usually due to misuse, not the framework itself. To uncover problems before they affect production, enable diagnostics like SQL and Hibernate statistics logging. By logging SQL queries and detailed statistics, you can observe what Hibernate sends to the database and identify key metrics like the number of queries and execution time.

One common cause of performance issues is the N+1 problem, where Hibernate generates 1 + N queries instead of a single query. There are three strategies to address N+1: JOIN FETCH, batch fetching, and DTO projections. JOIN FETCH allows you to load related data in a single SQL query using a JOIN, while batch fetching retrieves multiple entities in a single query using an IN clause.

DTO projections return only the necessary fields, avoiding the creation of managed entities and eliminating N+1 altogether. Choose the appropriate strategy based on the specific access scenario.

The OSIV (Open Session in View) anti-pattern is another performance issue that arises when the Hibernate session remains open throughout an HTTP request, leading to unexpected queries and connection pool issues. To mitigate this, disable OSIV in production by setting spring.jpa.open-in-view to false. This will make lazy loading issues explicit, forcing you to address them correctly using strategies like JOIN FETCH, @EntityGraph, or DTOs.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

AWS Agent Registry: How Runtime Tool Discovery Replaces Hardcoded Agent Wiring

Hardcoded tool catalogs break when your agent needs to choose between 200 MCP servers instead of five. AWS Agent Registry solves this by moving tool discovery from build time to runtime.

  • AWS Agent Registry replaces hardcoded tool wiring with runtime tool discovery.
  • Three-step process: Discover, Instantiate, Execute.
  • Metadata includes unique ID, description, schema definitions, and tags.

DRY vs WET Code: When Repeating Yourself Is Actually Better

Every developer has heard the advice: "Don't Repeat Yourself." But what if following that principle too aggressively makes your code harder to maintain?

  • DRY principle advocates minimizing code duplication.
  • WET approach, or Write Everything Twice, embraces code repetition.
  • Rule of Three suggests evaluating duplication at three points.

PNG to WebP for Online Store Product Images: Speed Up Product Pages

Product images are the heaviest thing on most e-commerce pages, and they're also the thing that matters most — they're what the customer actually looks at.

  • Converting PNG to WebP reduces product page file sizes
  • WebP maintains visual quality while optimizing for speed
  • Simple conversion process improves conversion rates and SEO

More from Wednesday 21 October →