Code Like A Girl
Read post

Hibernate Turned 11,000 Records Into 50 Million Rows

This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).

A bulk-import job processing 15,000 transaction templates caused an out-of-memory crash due to a Hibernate Cartesian product bug. A single JPQL query using JOIN FETCH on two collections simultaneously caused Hibernate to cross-join them, turning ~11,000 records into 50 million rows in memory. The bug was invisible in small-scale tests because the collections were mapped as Set rather than List (which would have thrown a MultipleBagFetchException at startup). The fix involved splitting the query into two separate fetches per collection, using @BatchSize for batch loading, and periodically flushing and clearing the Hibernate session during long-running imports. The result was a 9x reduction in row count and 15x improvement in processing time.

    #java
Jul 11•7m read time•From code.likeagirl.io
Post cover image
Table of contents
The Query That Looked Totally FineQuick Refresher: Eager vs Lazy LoadingHere’s What’s Actually HappeningGet JAGRITI BANSAL ’s stories in your inboxWhy Nobody Caught It in ReviewHow We Tracked It DownThe Fix, in Three PartsDid It Actually WorkWhat I’d Tell You to Watch For
91K Impressions1 Comment
Code Like A Girl's image
Code Like A Girl

Colkgirl shines a spotlight on women in tech, diversity, and inclusion initiatives, providing a plat...

281 Followers

•

3.9K Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard