openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rtselvan <rtsel...@gmail.com>
Subject Re: overriding datasource in the persistent unit
Date Sun, 08 Nov 2009 00:55:27 GMT

Thanks Guys! 

Let me try that, it looks pretty simple



Michael Dick wrote:
> 
> Adding to Milosz response.
> 
> The property keys that you want are javax.persistence.jtaDataSource and
> javax.persistence.nonJtaDataSource (for jta-data-source and
> non-jta-data-source respectively)
> 
> For example :
>         Map<String, Object> props = new HashMap<String, Object>();
>         props.put("javax.persistence.jtaDataSource", "jdbc/override");
>         props.put("javax.persistence.nonJtaDataSource",
> "jdbc/overrideNonJTA");
>         EntityManagerFactory emf =
> Persistence.createEntityManagerFactory(getPersistenceUnitName(), props);
> 
> In earlier versions of OpenJPA you can use openjpa.ConnectionFactoryName
> for
> jta-data-source and openjpa.ConnectionFactory2Name for
> non-jta-data-source.
> 
> Hope this helps,
> -mike
> 
> On Sat, Nov 7, 2009 at 2:41 PM, MiƂosz Tylenda <mtylenda@o2.pl> wrote:
> 
>> Hello!
>>
>> > >
>> > > 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.
>>
>> Regards,
>> Milosz
>>
>>
> 
> 

-- 
View this message in context: http://n2.nabble.com/overriding-datasource-in-the-persistent-unit-tp3962382p3966416.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message