On Fri, Nov 6, 2009 at 8:10 PM, rtselvan <[email protected]> wrote:

>
> My application is a multi-tenant app, I would need to override the
> datasource
> at runtime when creating the entitymanager factory based on the client
> code/name.
>
> Does OpenJPA support that?


In a month or two I will be modifying my application to do just this sort of
thing. I assume by "multi-tenant" you mean someone will login as a user
under one of many organizations and the user will then have access to one of
many persistence units that correspond to the organizations? I have much
more to do than selecting the right persistence unit / em factory, but I'm
interested in whatever you come up with. I hadn't considered that OpenJPA
might support it, I figured I'd have to instantiate all the factories when
the app starts up, then use the URL the user accesses the app with to map to
the right factory. It actually seems fairly easy, but if OpenJPA supports
some mechanism already, all the better.

I currently use a static factory with a ThreadLocal entity manager. So I
want my business logic to continue to be able to pick the entity manager
from the current thread. This means I need to set up the ThreadLocal state
at the beginning of the event thread to be able to create an entity manager
from the right factory, presumably by mapping the URL to the factory.

Those are my thoughts thus far.

-- 
Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
mailto:[email protected]

Reply via email to