If you want to build systems that scale, you must stop treating the database as a mere storage mechanism and start optimizing the data access layer. Here is how.
By respecting the relational database engine and understanding the internals of Hibernate/JPA, you can achieve performance that rivals hand-coded JDBC, while retaining the productivity benefits of the object-relational mapping. High-performance Java Persistence.pdf
Each click of "View Order History" triggered what she now saw as a cascade of inefficiency: a JPQL query so lazy it fetched only IDs, then a separate SELECT for each of the 200 orders, then another for each item inside those orders, then another for the shipping details. The infamous N+1 problem. The database wasn't slow; it was being waterboarded by thousands of tiny, desperate queries. If you want to build systems that scale,