{"record":{"id":"acd1c71c5208617a","repo":"hibernate/hibernate-orm","slug":"could-not-initialize-proxy-no-session","errorCode":null,"errorMessage":"Could not initialize proxy [{}#{}] - no session","messagePattern":"Could not initialize proxy \\[(.+?)#(.+?)\\] - no session","errorType":"exception","errorClass":"LazyInitializationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java","lineNumber":178,"sourceCode":"\t}\n\n\t@Override\n\tpublic final void unsetSession() {\n\t\tprepareForPossibleLoadingOutsideTransaction();\n\t\tsession = null;\n\t\treadOnly = false;\n\t\treadOnlyBeforeAttachedToSession = null;\n\t}\n\n\t@Override\n\tpublic final void initialize() throws HibernateException {\n\t\tif ( !initialized ) {\n\t\t\ttry {\n\t\t\t\tif ( allowLoadOutsideTransaction ) {\n\t\t\t\t\tpermissiveInitialization();\n\t\t\t\t}\n\t\t\t\telse if ( session == null ) {\n\t\t\t\t\tthrow new LazyInitializationException( \"Could not initialize proxy [\"\n\t\t\t\t\t\t\t+ entityName + \"#\" + id + \"] - no session\" );\n\t\t\t\t}\n\t\t\t\telse if ( !session.isOpenOrWaitingForAutoClose() ) {\n\t\t\t\t\tthrow new LazyInitializationException( \"Could not initialize proxy [\"\n\t\t\t\t\t\t\t+ entityName + \"#\" + id + \"] - the owning session was closed\" );\n\t\t\t\t}\n\t\t\t\telse if ( !session.isConnected() ) {\n\t\t\t\t\tthrow new LazyInitializationException( \"Could not initialize proxy [\"\n\t\t\t\t\t\t\t+ entityName + \"#\" + id + \"] - the owning session is disconnected\" );\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\ttarget = immediateLoad( session );\n\t\t\t\t\tinitialized = true;\n\t\t\t\t\tcheckTargetState( session );\n\t\t\t\t}\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\tif ( session != null && !session.isTransactionInProgress() ) {","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java#L160-L196","documentation":"Error \"Could not initialize proxy [{}#{}] - no session\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A lazy proxy is accessed outside the lifecycle of its owning Hibernate Session.","commonSituations":"LazyInitializationException-style failures when rendering entities after the transaction/Session closed, common in web views and serialization.","solutions":["Initialize the proxy while its owning Session is still open (Hibernate.initialize or access within the session).","Enable Open Session in View or fetch eagerly if data is needed outside the session."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}