openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rtselvan <>
Subject Re: overriding datasource in the persistent unit
Date Sun, 08 Nov 2009 00:53:19 GMT

There may be some difference in what you are doing though. I have one only
persistence unit in the XML file and connecting to different database based
on the user/organization. This avoids to creating a lot of persistence unit
and as well, ability to add additional organization without having change
the persistence unit xml file.

Daryl Stultz wrote:
> On Fri, Nov 6, 2009 at 8:10 PM, rtselvan <> 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.

View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message