LazyInitializationException Java Origin: Application & API Last updated 14 Oct 2026

org.hibernate.LazyInitializationException: could not initialize proxy - no Session

A lazy-loaded association was accessed after the Hibernate session/transaction closed.

Exact message you may see could not initialize proxy - no Sessionfailed to lazily initialize a collection
Seen on: Java

Meaning

Lazy collections and proxies load on first access, which needs an open session. Accessing them in the controller/view or during JSON serialization after the transaction ended fails.

Common causes

  • Accessing lazy relations outside @Transactional
  • Serializing entities to JSON after the service returns
  • Open Session in View disabled

⚡ Quick fix

  1. Fetch what you need in the query (JOIN FETCH / @EntityGraph)
  2. Map to DTOs inside the transaction
  3. Mark the service method @Transactional(readOnly = true)

Detailed fix by platform

Java

  1. @Query("select o from Order o join fetch o.items where o.id = :id")

How to diagnose

  1. Association — Which relation?
  2. Boundary — Where does the transaction end?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

Hibernate ConstraintViolationException — org.hibernate.exception.ConstraintViolationException: could not execute statement (Java)Hibernate ConstraintV…InvalidDefinitionException — com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class X and no properties discovered (Java)InvalidDefinitionExce…N+1 queries — Performance: N+1 query problem (one query per row in a loop) (SQL)N+1 queriesNonUniqueResultException — IncorrectResultSizeDataAccessException: query did not return a unique result: 2 (Java)NonUniqueResultExcept…SequelizeConnectionRefusedError — SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:5432 (Node.js)SequelizeConnectionRe…SQLAlchemy IntegrityError — sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint (Python)SQLAlchemy IntegrityE…SQLAlchemy OperationalError — sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) connection to server … failed (Python)SQLAlchemy Operationa…TransientObjectException — org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing (Java)TransientObjectExcept…LazyIniti…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.