Your 2 best options to fix Hibernate’s MultipleBagFetchException

Your 2 best options to fix Hibernate’s MultipleBagFetchException

You probably learned that you should use FetchType.LAZY for all of your associations. It ensures that Hibernate initializes an association when you use it and doesn’t spend any time getting data you don’t need. Unfortunately, this introduces a new issue. You now need to use a JOIN FETCH clause or an EntityGraph to fetch the…

LazyInitializationException – What it is and the best way to fix it
|

LazyInitializationException – What it is and the best way to fix it

The LazyInitializationException is one of the most common exceptions when working with Hibernate. There are a few easy ways to fix it. But unfortunately, you can also find lots of bad advice online. The proclaimed fixes often replace the exception with a hidden problem that will cause trouble in production. Some of them introduce performance…

Key annotations you need to know when working with JPA and Hibernate

Key annotations you need to know when working with JPA and Hibernate

When you start learning and using Hibernate and JPA, the number of annotations might be overwhelming. But as long as you rely on the defaults, you can implement your persistence layer using only a small subset of them. After you have mastered the basic annotations, you can take a look at additional customization options. You…