配置数据源 - tomee.xml,persistence.xml [英] Configuring data source - tomee.xml, persistence.xml

查看:461
本文介绍了配置数据源 - tomee.xml,persistence.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一些使用JPA项目的EJB,它将一些实体映射/保存到mysql数据库。
我已经在persistence.xml中定义了持久化单元,如下所示:

I'm doing some EJB with JPA project that maps/persists some entities to mysql database. I have defined persistence unit in persistence.xml like this:

  <persistence-unit name="MyAppPU" transaction-type="JTA">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <jta-data-source>MyAppDS</jta-data-source>
    <properties>
      <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
      <property name="openjpa.jdbc.DBDictionary" value="mysql" />
      <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO" />
    </properties>
  </persistence-unit>

然后,在tomee / conf / tomee.xml文件中,我已经定义了这样的数据源: p>

Then, in tomee/conf/tomee.xml file i have defined data source like this:

<Resource id="MyAppDS" type="DataSource">
    JdbcDriver          com.mysql.jdbc.Driver
    JdbcUrl             jdbc:mysql://127.0.0.1:3306/MyAppDB
    UserName            root
    Password            123
    JtaManaged          true
    DefaultAutoCommit   false
</Resource>

所有这些都可以正常运行,我创建MyApp.jar,将其部署到TomEE服务器,并测试它在数据库中获取mysql表。
我的问题是有没有其他地方可以定义数据源资源?
或者它必须在tomee / conf / tomee.xml文件中?
可以将它定义在应用程序结构内部的某些xml文件中,并将其部署到应用程序jar文件到服务器中?

All this works fine, i create MyApp.jar, deploy it to TomEE server, test it and i get mysql tables in database. My question is "Is there any other place where I could define data source resource?" Or it has to be in tomee/conf/tomee.xml file? Can it be defined somewhere inside application structure, in some xml file, and deployed inside apps jar file to server?

推荐答案

p>这是JNDI数据源的全部要点,可将其外部化到应用程序之外,因此您可以在不重新编译或重新打包的情况下对其进行修改。所以最好以这种方式离开。

That's the whole point of a JNDI data source, to externalize it outside of your application, so you can modify it without recompiling or repackaging. So it is better to leave it this way.

为了测试目的,一些EE服务器(如JBoss(Wildfly))可以让您在项目中进行定义。

For testing purpose, some EE server such as JBoss (Wildfly) let you define this in your project.

这篇关于配置数据源 - tomee.xml,persistence.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆