{"record":{"id":"914349144c5ada01","repo":"hibernate/hibernate-orm","slug":"proxies-cannot-be-fetched-by-a-stateless-session","errorCode":null,"errorMessage":"proxies cannot be fetched by a stateless session","messagePattern":"proxies cannot be fetched by a stateless session","errorType":"exception","errorClass":"SessionException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java","lineNumber":1364,"sourceCode":"\t\t\tfor ( Object entity : entities ) {\n\t\t\t\tdoRefresh( bestGuessEntityName( entity ), entity, LockMode.NONE );\n\t\t\t}\n\t\t}\n\t\tcatch ( MappingException e ) {\n\t\t\tthrow getExceptionConverter().convert( new IllegalArgumentException( e.getMessage(), e ) );\n\t\t}\n\t\tcatch ( RuntimeException e ) {\n\t\t\tthrow getExceptionConverter().convert( e );\n\t\t}\n\t\tfinally {\n\t\t\tafterOperation();\n\t\t}\n\t}\n\n\t@Override\n\tpublic Object immediateLoad(@Nonnull String entityName, @Nonnull Object id) {\n\t\tif ( getPersistenceContextInternal().isLoadFinished() ) {\n\t\t\tthrow new SessionException( \"proxies cannot be fetched by a stateless session\" );\n\t\t}\n\t\t// unless we are still in the process of handling a top-level load\n\t\treturn get( entityName, id );\n\t}\n\n\t@Override\n\tpublic void initializeCollection(@Nonnull PersistentCollection<?> collection, boolean writing) {\n\t\tcheckOpen();\n\t\tfinal var persistenceContext = getPersistenceContextInternal();\n\t\tfinal var ce = persistenceContext.getCollectionEntry( collection );\n\t\tif ( ce == null ) {\n\t\t\tthrow new HibernateException( \"no entry for collection\" );\n\t\t}\n\t\tif ( !collection.wasInitialized() ) {\n\t\t\tfinal var loadedPersister = ce.getLoadedPersister();\n\t\t\tfinal Object loadedKey = ce.getLoadedKey();\n\t\t\tif ( loadedPersister == null ) {\n\t\t\t\tthrow new AssertionFailure( \"collection entry has no loaded persister\" );","sourceCodeStart":1346,"sourceCodeEnd":1382,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java#L1346-L1382","documentation":"Error \"proxies cannot be fetched by a stateless session\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java:1364 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a regular Session if you need proxy/lazy fetching; stateless sessions do not support proxies.","Fetch the entity eagerly via the stateless session API instead of obtaining a proxy."],"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"}