Hi,
A situation similar to this was first reported to me back in August by the
author of an IBM Redbook (
http://www.redbooks.ibm.com/Redbooks.nsf/RedpieceAbstracts/sg247639.html?Open).
After I gave the "standard" answers of how this might be happening, I never
heard back.  So, I don't know if the problem was resolved by application
review or if they decided to live with the situation or what they did.  You
might want to reference the Redbook to see if there's any reference to the
situation.

First off, the tables should only be created if you are using the
SynchronizeMappings property.  Since I don't see that in your
persistence.xml, then I don't see how the tables are getting created
automatically.  Unless you have a different version of the persistence.xml
file that is getting picked up somehow.  Or, maybe your build process is
invoking the MappingTool?  Not sure.  I have never experienced anything like
that.

As far as creating the empty tables...  My guess is that your junit test is
(accidentally?) touching both entities, thus creating both tables.  If you
turn on the complete openjpa trace, you can see the processing of the
entities within each persistence unit.  So, either the entities are being
specified via some property or they are being touched by your application.
That's my guess.  The trace would give more data to go off of.

IIRC, there is one limitation with the MappingTool and/or
SynchronizeMappings that it will only process the entities in the first
defined persistence unit within a persistence.xml file.  But, even that
doesn't seem to apply in this case since you are indicating that the tables
are getting created via the second persistence unit.

Hopefully, the trace will show who is accessing what and causing the entity
processing and table creation.

Good luck,
Kevin


On Tue, Feb 10, 2009 at 11:36 AM, bongosdude <[email protected]> wrote:

>
> I defined two persistence units in my persistence.xml to connect to two
> different databases (one is MySQL and other to MS SQL) like below
>
> <persistence xmlns="http://java.sun.com/xml/ns/persistence";
>             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> version="1.0"
>             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd";>
>    <persistence-unit name="CallingCardUsersUnit">
>        <description>Entity Beans to db1</description>
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>        <non-jta-data-source>db_users_notx</non-jta-data-source>
>                <class>com.xyz.services.app.model.entity.users.User</class>
>
>  <class>com.xyz.services.app.model.entity.users.UserRole</class>
>
>  <class>com.xyz.services.app.model.entity.users.UserAccount</class>
>                <properties>
>                        <property name="/tmp/openjpa.log" value="SQL=TRACE"
> />
>                </properties>
>    </persistence-unit>
>
>    <persistence-unit name="DigittalkUnit">
>        <description>Entity Beans for db2</description>
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>        <non-jta-data-source>billing_notx</non-jta-data-source>
>        <class>com.xyz.services.app.model.entity.billing.BUser</class>
>        <class>com.xyz.services.app.model.entity.billing.BAccount</class>
>                <properties>
>                        <property name="/tmp/openjpa.log" value="SQL=TRACE"
> />
>                </properties>
>    </persistence-unit>
>
>
> </persistence>
>
>
> When my app first starts up and runs, I need to access entity
> com.xyz.services.app.model.entity.users.User, JPA tries to load entiry
> com.xyz.services.app.model.entity.users.User and then it tries to create
> table BUser and BAccount in the first persistence unit. BUser and BAccount
> are listed in second persistence unit. Also, BUser and BAccount are mapped
> to existing tables in second persistence unit.
>
> Can someone help me since I do not understand why it happens. Also, How can
> I turn of the auto create table.
>
> Thanks
> -B
> --
> View this message in context:
> http://n2.nabble.com/Problem-with-multi-persistence-units-tp2303818p2303818.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>

Reply via email to