*
The moose likes Object Relational Mapping and the fly likes Defining 2 separate databases in persistence.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Defining 2 separate databases in persistence.xml" Watch "Defining 2 separate databases in persistence.xml" New topic
Author

Defining 2 separate databases in persistence.xml

Ismael Upright
Ranch Hand

Joined: Feb 15, 2007
Posts: 166
Hello,

Suppose I need to define to have 2 separate databases backed on the Oracle: DBCustomers and DBProducts.

In DBCustomers I want to have tables: PersonalData and Orders.
In DBProducts I want to have tables: ProductData and Distribution.

My persistence.xml now:




The problem is that when I run it, both databases have all four tables: PersonalData, Orders, ProductData and Distribution. I want to separate these tables as I described in the beginning of this post.

Is there a way to do that?
Ismael Upright
Ranch Hand

Joined: Feb 15, 2007
Posts: 166
PS. As you can see, the IP address of host with Oracle is the same for both databases - only user differs. But as far as I know, different users in the Oracle have different schemas.
Ismael Upright
Ranch Hand

Joined: Feb 15, 2007
Posts: 166
Never mind, solved it.

The solution is to put the tag:

<exclude-unlisted-classes>true</exclude-unlisted-classes>

to every persistence unit.


Seems that the default beharior is to take the set all classes from all persistence units, and insert them into all databases. A bit strange default to me...
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Thanks for the update. Even though it looks like you're having a conversation with yourself, I actually found this interesting.

"When "<exclude-unlisted-classes>true</exclude-unlisted-classes>" is present in "persistence.xml", enclosing jar is not scanned for annotated classes."

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Defining 2 separate databases in persistence.xml
 
Similar Threads
Exception while getting transaction
Hibernate: Error getting property 'lastItem'
No Persistence provider for EntityManager named mockPersist
'hibernate.dialect' must be set when no Connection available
EjbQl Connection problem.......