{"record":{"id":"89c51eee0046988b","repo":"flowable/flowable-engine","slug":"entitymanagerfactory-is-null-89c51e","errorCode":null,"errorMessage":"entityManagerFactory is null","messagePattern":"entityManagerFactory is null","errorType":"exception","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/EntityManagerSessionFactory.java","lineNumber":34,"sourceCode":"import jakarta.persistence.EntityManagerFactory;\n\nimport org.activiti.engine.ActivitiIllegalArgumentException;\nimport org.activiti.engine.impl.interceptor.Session;\nimport org.activiti.engine.impl.interceptor.SessionFactory;\nimport org.flowable.variable.service.impl.types.EntityManagerSession;\n\n/**\n * @author Frederik Heremans\n */\npublic class EntityManagerSessionFactory implements SessionFactory {\n\n    protected EntityManagerFactory entityManagerFactory;\n    protected boolean handleTransactions;\n    protected boolean closeEntityManager;\n\n    public EntityManagerSessionFactory(Object entityManagerFactory, boolean handleTransactions, boolean closeEntityManager) {\n        if (entityManagerFactory == null) {\n            throw new ActivitiIllegalArgumentException(\"entityManagerFactory is null\");\n        }\n        if (!(entityManagerFactory instanceof EntityManagerFactory)) {\n            throw new ActivitiIllegalArgumentException(\"EntityManagerFactory must implement 'jakarta.persistence.EntityManagerFactory'\");\n        }\n\n        this.entityManagerFactory = (EntityManagerFactory) entityManagerFactory;\n        this.handleTransactions = handleTransactions;\n        this.closeEntityManager = closeEntityManager;\n    }\n\n    @Override\n    public Class<?> getSessionType() {\n        return EntityManagerSession.class;\n    }\n\n    @Override\n    public Session openSession() {\n        return new EntityManagerSessionImpl(entityManagerFactory, handleTransactions, closeEntityManager);","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/EntityManagerSessionFactory.java#L16-L52","documentation":"EntityManagerSessionFactory's constructor validates that the entityManagerFactory argument is non-null and throws ActivitiIllegalArgumentException immediately otherwise. JPA variable support requires a real jakarta.persistence.EntityManagerFactory to create EntityManagerSessions, so a null factory is rejected at session-factory construction time.","triggerScenarios":"new EntityManagerSessionFactory(null, handleTransactions, closeEntityManager) — typically the JPA config property (jpaEntityManagerFactory / entityManagerFactory bean) was never set or resolved to null.","commonSituations":"Spring context missing the EntityManagerFactory bean (JPA not configured); wiring the process engine configuration without jpaHandleTransaction/jpa close settings but a null factory; bean name typo in XML/Java config.","solutions":["Configure the EntityManagerFactory before creating the session factory (set jpaEntityManagerFactory in ProcessEngineConfiguration)","Ensure the Spring bean is defined and injected (LocalContainerEntityManagerFactoryBean)","Check that the property/bean reference name is spelled correctly and not resolving to null","Initialize JPA (persistence.xml, datasource) before engine startup"],"exampleFix":"// before\nprocessEngineConfiguration.setJpaEntityManagerFactory(null);\n// after\nprocessEngineConfiguration.setJpaEntityManagerFactory(entityManagerFactory); // injected Spring bean","handlingStrategy":"validation","validationCode":"// validate before constructing the session factory\nif (entityManagerFactory == null) {\n  throw new IllegalStateException(\"configure jpaEntityManagerFactory before engine startup\");\n}","typeGuard":"boolean validJpaFactory(Object emf) {\n  return emf instanceof jakarta.persistence.EntityManagerFactory;\n}","tryCatchPattern":"try {\n  processEngineConfiguration.setJpaEntityManagerFactory(emf);\n} catch (ActivitiIllegalArgumentException e) {\n  logger.error(\"EntityManagerFactory missing/invalid: \" + e.getMessage());\n  throw e;\n}","preventionTips":["Wire the JPA EntityManagerFactory bean before building the engine","Verify Spring bean injection with a startup assertion","Check persistence.xml/datasource initialization order","Fail fast at boot rather than at first variable access"],"tags":["jpa","configuration","null"],"backgroundTag":"null-argument","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}