getReference (and JpaRepository.getReferenceById) never hits the database. It returns an uninitialised proxy, and the SELECT happens on the first getter - which, outside the transaction, is a LazyInitializationException instead.
This topic is available to PRO members.
Open this topic Go PRO Sign in Create a free accountRun this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-08-25