英文:
How to configure transaction-type="JTA" programmatically (without persistence.xml")?
问题
我可以在配置的Java类中创建EntityManagerFactory时设置transaction-type为"JTA",而无需任何.xml配置吗?
英文:
Can I set transaction-type "JTA" when creating EntityManagerFactory in configuration java class without any .xml configs?
答案1
得分: 3
你可以尝试以以下方式覆盖javax.persistence.transactionType属性:
Map configOverrides = new HashMap();
configOverrides.put("javax.persistence.transactionType", "JTA");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("yourPersistenceUnitName", configOverrides);
但是如果在类路径中不存在META-INF/persistence.xml文件,可能会引发PersistenceException异常。
请参阅文档(2.2.2. 启动部分)。
英文:
You can try to override the javax.persistence.transactionType property in this way:
Map configOverrides = new HashMap();
configOverrides.put("javax.persistence.transactionType", "JTA");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("yourPersistenceUnitName", configOverrides);
But it looks like the PersistenceException exception will be raised if the META-INF/persistence.xml file is absent in your classpath.
See the documentation (section 2.2.2. Bootstrapping).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论