Skip to content

Tag: database

JPA Entity Graph

A common criticism of JPA is that it generates inefficient SQL, often resulting in several queries where one would do. In particular, it’s prone to the n+1 problem where it loads an entity with one query and then runs an additional query for each item in an owned collection. JPA Entity Graph is one way to avoid this. It allows the application developer to closely control how related entities are fetched. You can use JPA Entity Graph to tell JPA to load a complex web of entities with a single query and significantly improve performance of your application.

Generate database schema DDL from Hibernate hbm mappings

Hibernate can be used to map Java classes to existing database tables. More often, the Java classes come first and the database is created around the mapping. If that’s the case, you’ll want to define your database schema directly from Hibernate mappings rather than hand crafting DDL scripts. Hibernate offers a couple of ways to do this.