简体   繁体   English

部署时在persistence.xml中管理jta-data-source

[英]Manege jta-data-source in persistence.xml on deploy

There is way to change jta-data-source in persistence.xml on runtime and stay in manage mode 有一种方法可以在运行时在persistence.xml中更改jta-data-source并保持在管理模式下

@PersistenceContext(unitName="BookUnit")
private EntityManager em;

(i know i can use EntityManagerFactory but i want to stay in managed mode like i wrote before) (我知道我可以使用EntityManagerFactory,但我想像我之前写的那样保持在托管模式下)

I have more then one environment (local,test,prod) and for each environment there is different jndi datasource i don't wont to change the persistence.xml file for each environment i want to manage it in the code 我有一个以上的环境(本地,测试,产品),并且对于每个环境,都有不同的jndi数据源,我不会为每个要在代码中管理它的环境更改persistence.xml文件

There are multiple ways of achieving this kind of functionality - 有多种方法可以实现这种功能-

1) Use environmental variables in persistence.xml and initialize them appropriately based on your environment, ie, while starting the server init this variable to appropriate value 1)在persistence.xml中使用环境变量,并根据您的环境适当地对其进行初始化,即在启动服务器时将此变量初始化为适当的值

2) As your instances for dev, test & production would be different, for the same JNDI name configure your datasource appropriately. 2)由于开发,测试和生产的实例会有所不同,因为相同的JNDI名称会适当地配置您的数据源。

Ex: on your dev server configure your datasoruce to connect to dev DB, similarly for test environment to test DB and in production to Production DB. 例如:在开发服务器上,将您的数据源配置为连接到开发数据库,​​类似地,用于测试环境以测试数据库以及在生产环境中使用生产数据库。

I would always go with Option 2 , as this is standard way of doing things. 我将始终选择选项2 ,因为这是标准的处理方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 把什么放到jos-data-persistence.xml中? - What to put into jta-data-source of persistence.xml? 从Weblogic部署Plan.xml编辑Persistence.xml jta-data-source - Editing Persistence.xml jta-data-source from Weblogic deployment Plan.xml JPA:通过覆盖数据源,在JSE和JUnit中将jp-data-source与persistence.xml一起使用 - JPA: Reuse persistence.xml with jta-data-source in JSE and JUnit by overriding the datasource 如何读取persistence.xml的标记值 <jta-data-source> 从文件config.properties中输入 - How I can do to read the tag value for my persistence.xml <jta-data-source> in from a file config.properties 我怎么能定义 <non-jta-data-source></non-jta-data-source> 在persistence.xml中? - How can i defind <non-jta-data-source> </non-jta-data-source> in persistence.xml? persistence.xml transaction-type =“ JTA” - persistence.xml transaction-type=“JTA” SE应用程序的JPA persistence.xml数据源 - JPA persistence.xml data-source for SE app 从persistence.xml初始化Flyway数据源 - Initialize Flyway data source from persistence.xml 如何将DRY应用于Liquibase数据源config和persistence.xml? - How to apply DRY for Liquibase data source config and persistence.xml? 如何在Web项目中部署persistence.xml? - How to deploy persistence.xml in a web project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM