Lazy Loading

Spring bean lazy init

Spring @Lazy Loaded Beans

Spring @Lazy allows lazy bean creation either to specific beans or we can configure the lazy loading globally at the application level.

Hibernate.initialize(): Load a Proxy or a Lazy Collection

Hibernate.initialize() loads a lazy proxy or a lazy collection while the EntityManager is open, so the data is usable after the transaction ends. Examples with the SQL, unproxy(), size(), the closed-session error and the N+1 alternatives.

Hibernate Lazy Loading: FetchType LAZY vs EAGER with SQL

Hibernate lazy loading reads an association only when the code first uses it. See the SQL that LAZY and EAGER run, how proxies and PersistentBag work, and how to fix LazyInitializationException with join fetch, entity graphs, Hibernate.initialize() or a DTO projection.

getReference vs find: JPA EntityManager Methods Compared

EntityManager find() loads an entity with a SELECT or returns null, while getReference() returns a proxy without SQL. See when each runs SQL, when EntityNotFoundException and LazyInitializationException are thrown, and how to set a foreign key without loading the entity.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.