How to activate Hibernate Statistics to analyze performance issues
|

How to activate Hibernate Statistics to analyze performance issues

Did you ever ask yourself why a server request took ages on the production system while your local test system was just fine?Well, we all had these situations, and we will have several more of them in the future. In my experience, strange performance drops are often related to slow database queries. But which query…

5 ways to initialize lazy associations and when to use them
| |

5 ways to initialize lazy associations and when to use them

Lazy loading of associations between entities is a well established best practice in JPA. Its main goal is to retrieve only the requested entities from the database and load the related entities only if needed. That is a great approach if you only need the requested entities. But it creates additional work and can be…

JPA Entity Graphs: How to Dynamically Define and Use an EntityGraph
| |

JPA Entity Graphs: How to Dynamically Define and Use an EntityGraph

This is my second post on Entity Graphs. The first post described the usage of named entity graphs. These can be used to define a graph of entities and/or attributes at compile time that shall be fetched with a find or query method. Dynamic entity graphs do to the same but in a dynamic way. This…

JPA Entity Graphs: How to Define and Use a @NamedEntityGraph
| |

JPA Entity Graphs: How to Define and Use a @NamedEntityGraph

Lazy loading is often an issue with JPA. You have to define at the entity if you want to use FetchType.LAZY (default) or FetchType.EAGER to load the relation and this mode is always used. FetchType.EAGER is only used if we want to always load the relation. FetchType.LAZY is used in almost all of the cases…