org.apache.openjpa.persistence.InvalidStateException:此代理未配置为使用托管事务

org.apache.openjpa.persistence.InvalidStateException: This broker is not configured to use managed transactions

我正在尝试配置 camel jpa 组件,当我 运行 测试用例时,出现此错误

"org.apache.openjpa.persistence.InvalidStateException: This broker is not configured to use managed transactions."

但是如果我没有使用任何事务管理器,它会采用默认的事务管理器并且一切顺利

我的配置

`@JndiBind("jpa")
@Provides*/
@Singleton
public JpaComponent getJpa(JpaVendorAdapter vendorAdapter){
    JpaComponent jpa = new JpaComponent();
    LocalEntityManagerFactoryBean fBean = new LocalEntityManagerFactoryBean();
    fBean.setJpaVendorAdapter(vendorAdapter);
    fBean.setPersistenceUnitName("camel");
    fBean.afterPropertiesSet();
    EntityManagerFactory entityManagerFactory = fBean.getNativeEntityManagerFactory();
    JpaTransactionManager txMgr = new JpaTransactionManager();
    txMgr.setEntityManagerFactory(entityManagerFactory);

    jpa.setEntityManagerFactory(entityManagerFactory);

    jpa.setTransactionManager(txMgr);

    return jpa;
}`

问题在于在您的代码中获取 EntityManager 对象。

    EntityManagerFactory entityManagerFactory = fBean.getObject();

    JpaTransactionManager txMgr = new JpaTransactionManager();
    txMgr.setEntityManagerFactory(entityManagerFactory);
    txMgr.afterPropertiesSet();

    jpa.setEntityManagerFactory(entityManagerFactory);
    jpa.setTransactionManager(txMgr);