Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 85941 invoked from network); 8 Nov 2009 00:53:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Nov 2009 00:53:43 -0000 Received: (qmail 3960 invoked by uid 500); 8 Nov 2009 00:53:43 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 3887 invoked by uid 500); 8 Nov 2009 00:53:42 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 3877 invoked by uid 99); 8 Nov 2009 00:53:42 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Nov 2009 00:53:42 +0000 X-ASF-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00 X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of lists+1214986160035-208411@n2.nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Nov 2009 00:53:40 +0000 Received: from tervel.nabble.com ([192.168.236.150]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1N6w1v-0002gW-E7 for users@openjpa.apache.org; Sat, 07 Nov 2009 16:53:19 -0800 Date: Sat, 7 Nov 2009 16:53:19 -0800 (PST) From: rtselvan To: users@openjpa.apache.org Message-ID: <1257641599426-3966405.post@n2.nabble.com> In-Reply-To: References: <1257556253449-3962382.post@n2.nabble.com> Subject: Re: overriding datasource in the persistent unit MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: rtselvan 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. > http://www.6degrees.com > mailto:daryl@6degrees.com > > -- View this message in context: http://n2.nabble.com/overriding-datasource-in-the-persistent-unit-tp3962382p3966405.html Sent from the OpenJPA Users mailing list archive at Nabble.com.