{"record":{"id":"861f9d786848bef2","repo":"hibernate/hibernate-orm","slug":"sessionimplementor-is-neither-session-nor-stateles","errorCode":null,"errorMessage":"sessionImplementor is neither Session nor StatelessSession","messagePattern":"sessionImplementor is neither Session nor StatelessSession","errorType":"exception","errorClass":"IdentifierGenerationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/id/IdentifierGeneratorHelper.java","lineNumber":140,"sourceCode":"\n\tprivate static Object identifier(\n\t\t\tSharedSessionContractImplementor session,\n\t\t\tEntityType foreignValueSourceType,\n\t\t\tObject associatedEntity) {\n\t\tfinal String associatedEntityName = foreignValueSourceType.getAssociatedEntityName();\n\t\ttry {\n\t\t\treturn getEntityIdentifierIfNotUnsaved( associatedEntityName, associatedEntity, session );\n\t\t}\n\t\tcatch (TransientObjectException toe) {\n\t\t\tif ( session instanceof Session statefulSession ) {\n\t\t\t\tstatefulSession.persist( associatedEntityName, associatedEntity );\n\t\t\t\treturn session.getContextEntityIdentifier( associatedEntity );\n\t\t\t}\n\t\t\telse if ( session instanceof StatelessSession statelessSession ) {\n\t\t\t\treturn statelessSession.insert( associatedEntityName, associatedEntity );\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new IdentifierGenerationException(\"sessionImplementor is neither Session nor StatelessSession\");\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate static EntityType entityType(String propertyName, EntityPersister entityDescriptor) {\n\t\tif ( entityDescriptor.getPropertyType( propertyName ) instanceof EntityType entityType ) {\n\t\t\t// the normal case\n\t\t\treturn entityType;\n\t\t}\n\t\telse {\n\t\t\t// try identifier mapper\n\t\t\tfinal String mapperPropertyName = IDENTIFIER_MAPPER_PROPERTY + \".\" + propertyName;\n\t\t\treturn (EntityType) entityDescriptor.getPropertyType( mapperPropertyName );\n\t\t}\n\t}\n\n\tpublic static ImplicitDatabaseObjectNamingStrategy getNamingStrategy(Properties params, ServiceRegistry serviceRegistry) {\n\t\tfinal String namingStrategySetting = coalesceSuppliedValues(","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/id/IdentifierGeneratorHelper.java#L122-L158","documentation":"Error \"sessionImplementor is neither Session nor StatelessSession\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when the session implementor passed to id generation is of an unexpected type.","commonSituations":"Typical situations: custom Session/StatelessSession wrappers; internal API misuse by extensions.","solutions":["This indicates an internal session type mismatch; ensure id generation runs within a standard Session or StatelessSession and upgrade Hibernate if it persists."],"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"}