IntelliJ Java IDE
The moose likes Object Relational Mapping and the fly likes JPA Misconception? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "JPA Misconception?" Watch "JPA Misconception?" New topic
Author

JPA Misconception?

Sean Brown
Greenhorn

Joined: Jun 11, 2007
Posts: 11
Hello Ranchhands.
To start off, I use the Java Persistence API (specifically Toplink Essentials) for the ORM layer, MySQL for the backend, and Servlet 2.5 for the frontend.

My application's requirement is that each user/client have their own database. Every one of these sql databases has the same exact same structure. When someone uses the service they provide an ID (namely as part of the uri, but it could be a form value) which is looked up in a registry and, if valid, is used as the SQL Database name for the connection.

Currently, I achieve this by overriding the toplink.jdbc.url property every time I create an EntityManager by passing a Map with that entry in it to Persistence.createEntityManagerFactory(String, Map). Although I use the same persistence unit, "user".

Now, it seems once that worked, we neglected to test if it would connect to the correct database, and not cache. And so, of course, that exact problem occurred during the public release. It turns out Toplink doesn't support multiple datasources per Persistence Unit.



My question to all of you out there is:
How do you all handle multiple clients with multiple databases in JPA?

If I could get a reply, that would be incredibly helpful.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16624

I think this thread a few days ago is doing the same thing

http://www.coderanch.com/t/217545/ORM/java/create-EntityManagerFactory

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
 
subject: JPA Misconception?
 
Threads others viewed
Regarding Good OO Design
Adding persistence.xml dynamically
iBATIS: Database Independance
Persistence provider
Spring + JPA + Hibernate and multiple Database connection
IntelliJ Java IDE