{"record":{"id":"a7daeaa6ffc36645","repo":"flowable/flowable-engine","slug":"entitymanagerfactory-is-null","errorCode":null,"errorMessage":"entityManagerFactory is null","messagePattern":"entityManagerFactory is null","errorType":"exception","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/types/EntityManagerSessionFactory.java","lineNumber":34,"sourceCode":"import jakarta.persistence.EntityManagerFactory;\n\nimport org.flowable.common.engine.api.FlowableIllegalArgumentException;\nimport org.flowable.common.engine.impl.interceptor.CommandContext;\nimport org.flowable.common.engine.impl.interceptor.Session;\nimport org.flowable.common.engine.impl.interceptor.SessionFactory;\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 FlowableIllegalArgumentException(\"entityManagerFactory is null\");\n        }\n        if (!(entityManagerFactory instanceof EntityManagerFactory)) {\n            throw new FlowableIllegalArgumentException(\"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(CommandContext commandContext) {\n        return new EntityManagerSessionImpl(entityManagerFactory, handleTransactions, closeEntityManager);","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-variable-service/src/main/java/org/flowable/variable/service/impl/types/EntityManagerSessionFactory.java#L16-L52","documentation":"The EntityManagerSessionFactory constructor validates its first argument: if the provided entityManagerFactory Object is null it throws FlowableIllegalArgumentException 'entityManagerFactory is null'. This factory wires JPA entity managers into Flowable's JPA variable type support.","triggerScenarios":"Constructing EntityManagerSessionFactory(null, handleTransactions, closeEntityManager), typically from process engine configuration where the JPA EntityManagerFactory property was not set (jpaEntityManagerFactory null in config).","commonSituations":"Enabling JPA variable support (jpaHandleTransaction/jpaCloseEntityManager) but forgetting to set jpaEntityManagerFactory; Spring wiring where the LocalContainerEntityManagerFactoryBean bean is missing or not injected yet; copy-pasted config from non-JPA projects.","solutions":["Configure processEngineConfiguration.setJpaEntityManagerFactory(entityManagerFactory) with a valid jakarta.persistence.EntityManagerFactory","In Spring, define/inject a LocalContainerEntityManagerFactoryBean and verify it is not null at wiring time","If you don't use JPA variables, disable the JPA configuration instead of passing null"],"exampleFix":"// before\nengineConfig.setJpaEntityManagerFactory(null);\n// after\nEntityManagerFactory emf = Persistence.createEntityManagerFactory(\"myPU\");\nengineConfig.setJpaEntityManagerFactory(emf);","handlingStrategy":"validation","validationCode":"if (entityManagerFactory == null) {\n    throw new IllegalArgumentException(\"jpaEntityManagerFactory must be configured before enabling JPA variable support\");\n}\nif (!(entityManagerFactory instanceof jakarta.persistence.EntityManagerFactory)) {\n    throw new IllegalArgumentException(\"object must implement jakarta.persistence.EntityManagerFactory\");\n}","typeGuard":"boolean isValidEmf(Object o) {\n    return o instanceof jakarta.persistence.EntityManagerFactory;\n}","tryCatchPattern":"try {\n    config.setJpaEntityManagerFactory(emf);\n} catch (org.flowable.common.engine.api.FlowableIllegalArgumentException e) {\n    log.error(\"JPA EntityManagerFactory missing/invalid: {}\", e.getMessage());\n    throw e;\n}","preventionTips":["Verify the JPA EntityManagerFactory bean is non-null before engine initialization","Fail fast in configuration assembly if the persistence unit could not be created","Only enable JPA-related config flags when a factory is actually available"],"tags":["java","flowable","jpa","null","configuration"],"backgroundTag":"null-argument","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}