persistence@glassfish.java.net

Deploy App twice on same server, use different DB Connection for each?

From: Grover Blue <grover.blue_at_gmail.com>
Date: Thu, 14 Aug 2008 13:38:18 -0500

I tried posting in various forums/listing, but I have yet to get a
response. Perhaps someone on this list can help me, and I'd really
appreciate it.

I have an application (AppAdmin.war) that I
deployed twice to Glassfish. After deployment, I changed the
persistence unit information for one of them so it would point to a
different database. It did not work, however, and the second
deployment still connects to the wrong DB. Below is what I did:

First deployment:
Application name: AppAdmin_Test
Application root: AppAdmin_Test


Second deployment:
Application name: AppAdmin_Prod
Application root: AppAdmin_Prod


After deployment, I modified two files for AppAdmin_Prod
AppAdmin_Prod\WEB-INF\classes\META-INF\persistence.xml
AppAdmin_Prod\WEB-INF\sun-web.xml


Here are the differences in the persistence.xml files:
*First deployment AppAdmin_Test):*
<?xml version="1.0" encoding="UTF-8"?>
<persistence
version="1.0" xmlns="[http://java.sun.com/xml/ns/persistence]<http://java.sun.com/xml/ns/persistence%5D>
"
xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance]<http://www.w3.org/2001/XMLSchema-instance%5D>
"
xsi:schemaLocation="[http://java.sun.com/xml/ns/persistence]<http://java.sun.com/xml/ns/persistence%5D>
[http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd]<http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd%5D>
">
<persistence-unit name="AppAdmin_Test" transaction-type="JTA">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<jta-data-source>jdbc/AppAdmin_Test</jta-data-source>
<class>com.mycompany.site.entity.ContentFile</class>
<class>com.mycompany.site.entity.Event</class>
<class>com.mycompany.site.entity.Product</class>
<class>com.mycompany.site.entity.Content</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="toplink.ddl-generation" value="create-tables"/>
<property name="[toplink.platform.class.name|
http://toplink.platform.class.name/]<http://toplink.platform.class.name/%5D>"
value="oracle.toplink.essentials.platform.database.SQLServerPlatform"/>
</properties>
</persistence-unit>
</persistence>{code}

*Second deployment (AppAdmin_Prod):*
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="[http://java.sun.com/xml/ns/persistence]<http://java.sun.com/xml/ns/persistence%5D>"
xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance]<http://www.w3.org/2001/XMLSchema-instance%5D>"
xsi:schemaLocation="[http://java.sun.com/xml/ns/persistence]<http://java.sun.com/xml/ns/persistence%5D>[
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd]<http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd%5D>
">
<persistence-unit name="AppAdmin_Prod" transaction-type="JTA">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<jta-data-source>jdbc/AppAdmin_Prod</jta-data-source>
<class>com.mycompany.site.entity.ContentFile</class>
<class>com.mycompany.site.entity.Event</class>
<class>com.mycompany.site.entity.Product</class>
<class>com.mycompany.site.entity.Content</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="toplink.ddl-generation" value="create-tables"/>
<property name="[toplink.platform.class.name|
http://toplink.platform.class.name/]<http://toplink.platform.class.name/%5D>"
value="oracle.toplink.essentials.platform.database.SQLServerPlatform"/>
</properties>
</persistence-unit>
</persistence>

The only change I made in sun-web.xml was the context-root (since it was
still showing as AppAdmin_Test - does this even matter post deployment?):
<context-root>/AppAdmin_Prod</context-root>

I then restarted the Sun App server, but the persistence unit being used by
application AppAdmin_Prod still appears to be using jdbc/AppAdmin_Test.

What am I missing?


Thanks.





-- 
Government big enough to supply everything...is big enough to take
everything you have. The course of history shows that as a government grows,
liberty decreases --- Thomas Jefferson
www.CampaignForLiberty.org