gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 07:53:17 25 4
gpt4 key购买 nike

我正在尝试配置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;
}`

最佳答案

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

    EntityManagerFactory entityManagerFactory = fBean.getObject();

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

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

关于java - org.apache.openjpa.persistence.InvalidStateException : This broker is not configured to use managed transactions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33044260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com