Java 指向错误数据源的TomEE
我使用一个TomEE实例部署2个Web应用程序。这两个应用程序使用不同的数据库和不同的实体 应用程序2集成到应用程序1中,因此我在运行时随时都需要这两个模式 我在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.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从未加载。我已经添加了它和它的工作。