{"record":{"id":"27d219b591ecbc96","repo":"hibernate/hibernate-orm","slug":"no-sessionfactory-with-uuid-uuid-and-name-na","errorCode":null,"errorMessage":"No SessionFactory with uuid [{uuid}] and name [{name}]","messagePattern":"No SessionFactory with uuid \\[(.+?)\\] and name \\[(.+?)\\]","errorType":"exception","errorClass":"InvalidObjectException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java","lineNumber":1547,"sourceCode":"\t\t\tif ( SESSION_FACTORY_LOGGER.isTraceEnabled() ) {\n\t\t\t\tSESSION_FACTORY_LOGGER.resolvedFactoryByUuid( uuid );\n\t\t\t}\n\t\t\treturn uuidResult;\n\t\t}\n\n\t\t// in case we were deserialized in a different JVM, look for an instance with the same name\n\t\t// (provided we were given a name)\n\t\tif ( name != null ) {\n\t\t\tfinal var namedResult = SessionFactoryRegistry.INSTANCE.getNamedSessionFactory( name );\n\t\t\tif ( namedResult != null ) {\n\t\t\t\tif ( SESSION_FACTORY_LOGGER.isTraceEnabled() ) {\n\t\t\t\t\tSESSION_FACTORY_LOGGER.resolvedFactoryByName( name );\n\t\t\t\t}\n\t\t\t\treturn namedResult;\n\t\t\t}\n\t\t}\n\n\t\tthrow new InvalidObjectException( \"No SessionFactory with uuid [\" + uuid + \"] and name [\" + name + \"]\" );\n\t}\n\n\t/**\n\t * Custom serialization hook used during {@code Session} serialization.\n\t *\n\t * @param oos The stream to which to write the factory\n\t * @throws IOException Indicates problems writing out the serial data stream\n\t */\n\tvoid serialize(ObjectOutputStream oos) throws IOException {\n\t\toos.writeUTF( getUuid() );\n\t\toos.writeBoolean( name != null );\n\t\tif ( name != null ) {\n\t\t\toos.writeUTF( name );\n\t\t}\n\t}\n\n\t/**\n\t * Custom deserialization hook used during {@code Session} deserialization.","sourceCodeStart":1529,"sourceCodeEnd":1565,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java#L1529-L1565","documentation":"Sessions (and the factory handle) serialize only a uuid+name reference; on deserialization readResolve() looks the SessionFactory up in SessionFactoryRegistry, first by uuid, then by name. If no factory with that uuid/name exists in the current JVM, java.io.InvalidObjectException is thrown. The design assumes the original factory is still alive wherever the Session is deserialized.","triggerScenarios":"Deserializing a Session (or a detached graph holding a serialized session reference) in a JVM where the originating SessionFactory was closed, never started, or has a different uuid — e.g. passing sessions between processes, or restarting the JVM then reading a cached blob.","commonSituations":"Distributed caches (Hibernate 2nd-level cache of detached objects, custom serialization in Redis/Hazelcast) that accidentally serialize a Session; session replication features in servlet containers touching Hibernate objects; dev-time serialization tests; serializing entities whose lazy proxies reference the factory.","solutions":["Never serialize live Sessions — detach/clear and serialize plain data or DTOs instead","If cross-JVM deserialization is required, boot a factory with the same name in the target JVM first so the name-based lookup succeeds","Keep the originating factory open in the same JVM while deserialization happens (close it after, not before)","For proxies/collections, serialize detached and reattach via session.merge/lock in a freshly opened session of a live factory"],"exampleFix":"// before\nbyte[] blob = serialize(activeSession); // stores only uuid+name reference\n// ... later, in a JVM without that factory:\nSession s = (Session) deserialize(blob); // InvalidObjectException\n\n// after\n// detach and move data, not infrastructure:\nList<Order> dto = session.createQuery(\"select o from Order o\", Order.class).getResultList();\nbyte[] blob = serialize(dto);\n// in the other JVM, open a NEW session on a live factory:\ntry (Session s = localFactory.openSession()) { ... }","handlingStrategy":"try-catch","validationCode":"// Before deserializing, ensure the original factory is alive under the same uuid/name\nSessionFactory known = SessionFactoryRegistry.INSTANCE.getNamedSessionFactory(factoryName);\nif (known == null) {\n    throw new IllegalStateException(\n        \"Start the SessionFactory named '\" + factoryName + \"' before deserializing sessions\");\n}","typeGuard":null,"tryCatchPattern":"try (ObjectInputStream in = new ObjectInputStream(bytes)) {\n    return (Session) in.readObject();\n} catch (InvalidObjectException e) {\n    // originating factory absent in this JVM — reattach against a live factory instead\n    throw new IllegalStateException(\n        \"SessionFactory referenced by the stream is not present in this JVM\", e);\n}","preventionTips":["Never serialize live Sessions or proxies; serialize detached DTOs and reattach via merge/lock on a live factory","If sessions must cross JVM restarts, give the factory a stable name and boot it before deserialization","Close factories only after all deserialization work finishes"],"tags":["hibernate","serialization","deserialization","session","registry"],"backgroundTag":"deserialization-failure","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}