openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MiƂosz Tylenda <>
Subject Re: overriding datasource in the persistent unit
Date Sat, 07 Nov 2009 20:41:17 GMT

> >
> > 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.

Have you tried calling Persistence.createEntityManagerFactory(String, Map)? The second parameter
should allow you to override any value you have set in persistence.xml, so in particular,
the data source name.


View raw message