【问题标题】:org.apache.openjpa.persistence.InvalidStateException: This broker is not configured to use managed transactionsorg.apache.openjpa.persistence.InvalidStateException:此代理未配置为使用托管事务
【发布时间】:2015-10-09 17:43:48
【问题描述】:

我正在尝试配置camel jpa组件,当我运行测试用例时,我收到了这个错误

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

但如果我不使用任何事务管理器,它会使用默认的,一切顺利

我的配置

`@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;
}`

【问题讨论】:

    标签: java hibernate jpa apache-camel openjpa


    【解决方案1】:

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

        EntityManagerFactory entityManagerFactory = fBean.getObject();
    
        JpaTransactionManager txMgr = new JpaTransactionManager();
        txMgr.setEntityManagerFactory(entityManagerFactory);
        txMgr.afterPropertiesSet();
    
        jpa.setEntityManagerFactory(entityManagerFactory);
        jpa.setTransactionManager(txMgr);
    

    【讨论】:

      猜你喜欢
      • 2014-07-01
      • 2013-01-09
      • 1970-01-01
      • 1970-01-01
      • 2014-02-22
      • 2022-11-29
      • 1970-01-01
      • 2017-07-30
      • 1970-01-01
      相关资源
      最近更新 更多