0

I'm using a single TomEE instance to deploy 2 Webapplications. Both applications use a different database and different entities.

Application 2 is integrated into Application 1, so I need both the schema anytime while running.

I have both DataSources configured in the tomee.xml like this:

<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>

In Application 1 I use this 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>

In Application 2 I use this 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="testDBPool2" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/testDBPool2</jta-data-source>
     </persistence-unit>
 </persistence>

When I tried to run application then it is throwing testDB.table1 is not exist, whereas actually the table1 exist in testDB2 schema not in testDB, I do not understand why it is pointing to wrong schema?

Angelo Fuchs
  • 9,825
  • 1
  • 35
  • 72
milind_db
  • 1,274
  • 5
  • 34
  • 56
  • Last sentence: Which application do you run there? If you run Application 1 then it naturally will attempt to look for table1 in testDB :) – Angelo Fuchs Jul 15 '14 at 08:43
  • Please do have a look at my edit of your code, it seems like these were typos, double check that you did not make them in your actual code (if you did and it works, reinsert them into the question and add an answer explaining the typos were the problem) – Angelo Fuchs Jul 15 '14 at 08:47
  • Thanks Angelo, actually these were the typos from my side..sorry for that. And Application 2 is integrated into Application 1, so I need both the schema anytime while running. – milind_db Jul 23 '14 at 03:57

1 Answers1

1

It seems to me that your persistence.xml of Application2 is never loaded. That is not so surprising as there already is a presistence.xml running for the context.

Try adding the entries from Application2 into Application 1 and see if that works out.

Alternatively have a look at this question: How can I make a JPA application access different databases? and see if it helps.

If both didn't work untie Application2 from Application1 and run them in different contexts so each of them has its own persistence.xml running then debug it again.

Community
  • 1
  • 1
Angelo Fuchs
  • 9,825
  • 1
  • 35
  • 72
  • 1
    thanks for your help Angelo, my persistence.xml of Application2 is never loaded. I have added it and its working. – milind_db Aug 25 '14 at 14:21