{"record":{"id":"f50da76c6ea05a90","repo":"flowable/flowable-engine","slug":"entitymanagerfactory-must-implement-jakarta-persi-f50da7","errorCode":null,"errorMessage":"EntityManagerFactory must implement 'jakarta.persistence.EntityManagerFactory'","messagePattern":"EntityManagerFactory must implement 'jakarta\\.persistence\\.EntityManagerFactory'","errorType":"exception","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/EntityManagerSessionFactory.java","lineNumber":37,"sourceCode":"import 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);\n    }\n\n    public EntityManagerFactory getEntityManagerFactory() {","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/variable/EntityManagerSessionFactory.java#L19-L55","documentation":"EntityManagerSessionFactory's constructor type-checks the entityManagerFactory argument against jakarta.persistence.EntityManagerFactory and throws ActivitiIllegalArgumentException if it is any other type. This catches callers passing a wrong-typed object (e.g. a Hibernate SessionFactory or a javax version of EntityManagerFactory after a namespace migration).","triggerScenarios":"new EntityManagerSessionFactory(someObject, ...) where someObject is non-null but not an instance of jakarta.persistence.EntityManagerFactory — e.g. javax.persistence.EntityManagerFactory from a pre-Jakarta JPA provider, or a raw Hibernate SessionFactory.","commonSituations":"Migrating from Java EE javax.* to Jakarta EE 9+ namespaces with mixed dependency versions; passing a Hibernate ORM SessionFactory instead of a JPA EntityManagerFactory; wrong bean injected by type confusion.","solutions":["Pass a jakarta.persistence.EntityManagerFactory instance (e.g. Spring's LocalContainerEntityManagerFactoryBean's getObject())","Upgrade/downgrade dependencies so all JPA classes come from the jakarta.persistence namespace, not javax.persistence","Replace direct Hibernate SessionFactory usage with the JPA EntityManagerFactory facade","Check import statements: jakarta.persistence.EntityManagerFactory, not javax.persistence"],"exampleFix":"// before\nimport javax.persistence.EntityManagerFactory; // wrong namespace\nprocessEngineConfiguration.setJpaEntityManagerFactory(javaxEmf);\n// after\nimport jakarta.persistence.EntityManagerFactory;\nprocessEngineConfiguration.setJpaEntityManagerFactory(jakartaEmf);","handlingStrategy":"type-guard","validationCode":"// check the exact type before constructing\nif (!(obj instanceof jakarta.persistence.EntityManagerFactory)) {\n  throw new IllegalStateException(\"expected jakarta.persistence.EntityManagerFactory, got \" + obj.getClass().getName());\n}","typeGuard":"boolean isJakartaEmf(Object o) {\n  return o instanceof jakarta.persistence.EntityManagerFactory;\n}","tryCatchPattern":"try {\n  processEngineConfiguration.setJpaEntityManagerFactory(emf);\n} catch (ActivitiIllegalArgumentException e) {\n  logger.error(\"wrong EntityManagerFactory type: \" + emf.getClass().getName(), e);\n  throw e;\n}","preventionTips":["Use jakarta.persistence imports consistently (Jakarta EE 9+)","Avoid mixing javax and jakarta JPA dependencies on the classpath","Pass the JPA EntityManagerFactory, not a Hibernate SessionFactory","Pin one JPA provider version in dependency management"],"tags":["jpa","type-mismatch","jakarta"],"backgroundTag":"type-mismatch","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"}