Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 指向错误数据源的TomEE_Java_Sql_Jdbc_Persistence_Apache Tomee - Fatal编程技术网

Java 指向错误数据源的TomEE

Java 指向错误数据源的TomEE,java,sql,jdbc,persistence,apache-tomee,Java,Sql,Jdbc,Persistence,Apache Tomee,我使用一个TomEE实例部署2个Web应用程序。这两个应用程序使用不同的数据库和不同的实体 应用程序2集成到应用程序1中,因此我在运行时随时都需要这两个模式 我在tomee.xml中配置了两个数据源,如下所示: <tomee> <Resource id="testDBPool" type="DataSource"> jdbcDriver = "com.mysql.jdbc.Driver" url = "jdbc:mysql://localhost:33

我使用一个TomEE实例部署2个Web应用程序。这两个应用程序使用不同的数据库和不同的实体

应用程序2集成到应用程序1中,因此我在运行时随时都需要这两个模式

我在
tomee.xml
中配置了两个
数据源,如下所示:

<tomee>
  <Resource id="testDBPool" type="DataSource">
    jdbcDriver = "com.mysql.jdbc.Driver"
    url = "jdbc:mysql://localhost:3306/testDB"
    username = "admin"
    password = "admin"
  </Resource>
</tomee>

<tomee>
  <Resource id="testDBPool2" type="DataSource">
    jdbcDriver = "com.mysql.jdbc.Driver"
    url = "jdbc:mysql://localhost:3306/testDB2"
    username = "admin"
    password = "admin"
  </Resource>
</tomee>
在应用程序2中,我使用这个
persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
  <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
   <persistence-unit name="testDBPool" transaction-type="JTA">   
      <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
      <jta-data-source>jdbc/testDBPool</jta-data-source>
   </persistence-unit>
 </persistence>
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">   
    <persistence-unit name="testDBPool2" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/testDBPool2</jta-data-source>
     </persistence-unit>
 </persistence>

org.eclipse.persistence.jpa.PersistenceProvider
jdbc/testDBPool2

当我试图运行应用程序时,它抛出了
testDB.table1不存在
,而实际上
table1
存在于
testDB2
模式中,不在
testDB
中,我不明白它为什么指向错误的模式?

在我看来,Application2的
persistence.xml
从未加载。这并不奇怪,因为已经有一个
presistence.xml
在为上下文运行

尝试将Application2中的条目添加到application1中,看看是否可行

或者看看这个问题:看看它是否有帮助


如果两者都不起作用,请将应用程序2从应用程序1中解开,并在不同的上下文中运行它们,这样每个应用程序都有自己的
persistence.xml
运行,然后再次调试它。

最后一句话:您在那里运行哪个应用程序?如果您运行应用程序1,那么它自然会尝试在testDB中查找table1:)请确实查看我对您的代码的编辑,看起来这些都是拼写错误,请仔细检查您在实际代码中是否没有使用它们(如果您使用了,并且有效,请将它们重新插入问题并添加一个解释拼写错误是问题的答案)谢谢你,安吉洛,事实上,这些是我这边的打字错误,对不起。应用程序2集成到应用程序1中,因此我在运行时随时都需要这两个模式。感谢您的帮助Angelo,我的persistence.xml应用程序2从未加载。我已经添加了它和它的工作。