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.
Run 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