You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Eduard Neuwirt <ed...@googlemail.com> on 2010/10/15 14:50:17 UTC

Struts, Spring, Hibernate and multiple Sessionfactories

Hello,

I am looking for an elegant solution for the following situation.

I have a multitenant struts/spring/hibernate application. Every tenant is
stored in own database within the same RDBMS. All databases has the same
schema. At the spring layer every tenant is represented as a datasource.
Because I use the Hibernate I have to create multiple SessionFactories to

How can I provide the correct Seesionfactory to the UserSession in struts.
Once I have is the tenantId stored in UserSession itself.

Please help
Eduard

Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Eduard Neuwirt <ed...@googlemail.com>.
 Raymond,

I found a possible solution here:
http://blog.springsource.com/2007/01/23/dynamic-datasource-routing

TenantId is hold in the Struts UserSession and shall be shared with
spring layer. The described solution uses ThreadLocal for this purpose.

Is it possible to provide this tenantId to the spring layer using
ThreadLocal ?

Is the UserSession bound to the ThreadLocal ?

Questions, questions :)

Regards and a lot of thanks to all
Eduard

Am 16.10.2010 16:50, schrieb Raymond He:
> To Li Ying and Dave New ton, multiple datasources is a common
> requirement in large scale e-commerce  and telecom application.
>                                     I used a data object to table
> mapping to do DB routing vertically, pk hashing to route horizontally.
>                                The routing operation should not be
> done by Struts, but by persistent layer.
>
> 2010/10/15, Eduard Neuwirt <ed...@googlemail.com>:
>> Hello,
>>
>> I am looking for an elegant solution for the following situation.
>>
>> I have a multitenant struts/spring/hibernate application. Every tenant is
>> stored in own database within the same RDBMS. All databases has the same
>> schema. At the spring layer every tenant is represented as a datasource.
>> Because I use the Hibernate I have to create multiple SessionFactories to
>>
>> How can I provide the correct Seesionfactory to the UserSession in struts.
>> Once I have is the tenantId stored in UserSession itself.
>>
>> Please help
>> Eduard
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Martin Gainty <mg...@hotmail.com>.
there is some confusion between accessing multiple datasources to (allow access to multiple database schemas) and
ThreadLocal which confines the java class variables access to the thread scope 

to clear up the confusion
A single thread can access one datasource with ThreadLocal variables
A single thread can also access multiple datasources as long as your thread local variables are unique to that datasource e.g.
datasource1
datasource2

ThreadLocal variables can be implemented in a distributed environment if you are managing the access to the object at the Thread Level 

you will need to consider where the values will be stored after the thread exits or otherwise reclaimed
one example would be implementing ThreadLocal<Serializable>
http://code.google.com/p/qdss-commons/source/browse/trunk/qdss-commons/src/java/org/qdss/commons/web/filter/AuthenticationFilter.java?spec=svn19&r=19

Martin 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> Date: Sun, 17 Oct 2010 12:46:22 +0000
> Subject: Re: Struts, Spring, Hibernate and multiple Sessionfactories
> From: raymond.kk.he@gmail.com
> To: user@struts.apache.org
> 
> 1)  In this multi-tenant app, it is OK. Every operation just need to
> access one tenant datasource in the thread .                2) Thread
> local is not appropriate in distributed architecture.  sometimes we
> should access 2 or more datasourses at the same time in ONE thread.
> 
> 2010/10/16, Dave Newton <da...@gmail.com>:
> > 2010/10/16 Raymond He <ra...@gmail.com>:
> >> To Li Ying and Dave New ton, multiple datasources is a common
> >> requirement in large scale e-commerce  and telecom application.
> >
> > I know; that's what I said.
> >
> > Dave
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> 
> -- 
> 从我的移动设备发送
> 
> *Kun He*  (or Raymond He)
> A Java Programmer
> Alibaba inc.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
 		 	   		  

Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Raymond He <ra...@gmail.com>.
1)  In this multi-tenant app, it is OK. Every operation just need to
access one tenant datasource in the thread .                2) Thread
local is not appropriate in distributed architecture.  sometimes we
should access 2 or more datasourses at the same time in ONE thread.

2010/10/16, Dave Newton <da...@gmail.com>:
> 2010/10/16 Raymond He <ra...@gmail.com>:
>> To Li Ying and Dave New ton, multiple datasources is a common
>> requirement in large scale e-commerce  and telecom application.
>
> I know; that's what I said.
>
> Dave
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

-- 
从我的移动设备发送

*Kun He*  (or Raymond He)
A Java Programmer
Alibaba inc.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Dave Newton <da...@gmail.com>.
2010/10/16 Raymond He <ra...@gmail.com>:
> To Li Ying and Dave New ton, multiple datasources is a common
> requirement in large scale e-commerce  and telecom application.

I know; that's what I said.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Raymond He <ra...@gmail.com>.
To Li Ying and Dave New ton, multiple datasources is a common
requirement in large scale e-commerce  and telecom application.
                                    I used a data object to table
mapping to do DB routing vertically, pk hashing to route horizontally.
                               The routing operation should not be
done by Struts, but by persistent layer.

2010/10/15, Eduard Neuwirt <ed...@googlemail.com>:
> Hello,
>
> I am looking for an elegant solution for the following situation.
>
> I have a multitenant struts/spring/hibernate application. Every tenant is
> stored in own database within the same RDBMS. All databases has the same
> schema. At the spring layer every tenant is represented as a datasource.
> Because I use the Hibernate I have to create multiple SessionFactories to
>
> How can I provide the correct Seesionfactory to the UserSession in struts.
> Once I have is the tenantId stored in UserSession itself.
>
> Please help
> Eduard
>

-- 
从我的移动设备发送

*Kun He*  (or Raymond He)
A Java Programmer
Alibaba inc.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Marshall Gunter <ma...@mate1inc.com>.
I have seen a horizontal partitioning of data using Hibernate that hides
the SessionFactories, etc in a ConfigUtil class. The idea goes something
like this.

The ConfigUtil establishes all SessionFactories and stores them in a map
with their associated identifier (ID, class, whatever you choose) as the
key. The ConfigUtil then has a call getSessionFactory(identifier) that
returns the SessionFactory for the identifier you submit.

On 10-10-15 09:43 AM, Li Ying wrote:
> We developed a multi-tenant app last year.
>
> But we didn't separate their data into different DB.
>
> Instead, we stored all data in one DB, and add
> a [tenant_id] column to all tables to distinguish
> which tenant it belong.
>
> I think this is a simpler solution.
>
> When you need to add new tenant,
> you can simply add new records to one DB,
> you don't have to create new DB and configure it in your executive environment.
>
> And, when you change your DB design,
> you don't have to do this in all the DBs.
>
>
>
>
> 2010/10/15 Eduard Neuwirt <ed...@googlemail.com>:
>   
>> Hello,
>>
>> I am looking for an elegant solution for the following situation.
>>
>> I have a multitenant struts/spring/hibernate application. Every tenant is
>> stored in own database within the same RDBMS. All databases has the same
>> schema. At the spring layer every tenant is represented as a datasource.
>> Because I use the Hibernate I have to create multiple SessionFactories to
>>
>> How can I provide the correct Seesionfactory to the UserSession in struts.
>> Once I have is the tenantId stored in UserSession itself.
>>
>> Please help
>> Eduard
>>     
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Frans Thamura <fr...@meruvian.org>.
Every extend mapp to different injection to what lli ying said


/m/

-----Original Message-----
From: Eduard Neuwirt <ed...@googlemail.com>
Date: Fri, 15 Oct 2010 16:37:56 
To: Struts Users Mailing List<us...@struts.apache.org>; <fr...@meruvian.org>
Subject: Re: Struts, Spring, Hibernate and multiple Sessionfactories

Hi Frans,

would you mind to explain it ? Different implementation of what ?

Regards
Eduard

2010/10/15 Frans Thamura <fr...@meruvian.org>

> How about make different implementation
>
> So
>
> Tenant1 extends tenanta
>
> Tenant2 extends tenantb
>
>
> /m/
>
> -----Original Message-----
> From: Eduard Neuwirt <ed...@googlemail.com>
> Date: Fri, 15 Oct 2010 16:16:35
> To: Struts Users Mailing List<us...@struts.apache.org>
> Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
> Subject: Re: Struts, Spring, Hibernate and multiple Sessionfactories
>
> Hi Li,
>
> thanks for the answer. I didn't get how does it work within the
> struts-spring plugins ? In this case ist the the question is how to access
> to the application context directly from struts session. I could not find
> any information in the docu.
>
>
> Regards
> Eduard
>
>
>
> 2010/10/15 Li Ying <li...@gmail.com>
>
> > If you want to use multi-DB for multi-tenant (let's say tenant01 and
> > tenant02)
> >
> > I think you can create config file should likes:
> >
> > <bean id="sessionFactory_tenant01" class="xxxxx">
> >  <property name="configLocation" value="cfg_tenant01.xml"/>
> > </bean>
> >
> > <bean id="sessionFactory_tenant02" class="xxxxx">
> >  <property name="configLocation" value="cfg_tenant02.xml"/>
> > </bean>
> >
> > and then, in your java code, you can get different bean instance for
> > different tenant via [ID],
> > code looks like:
> >  BeanFactory.getBean("sessionFactory_" + tenantID,SessionFactory.class);
> >
> >
> > You can read this document for more information:
> >
> >
> http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/beans/factory/BeanFactory.html#getBean%28java.lang.String,%20java.lang.Class%29
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>


Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Eduard Neuwirt <ed...@googlemail.com>.
Hi Frans,

would you mind to explain it ? Different implementation of what ?

Regards
Eduard

2010/10/15 Frans Thamura <fr...@meruvian.org>

> How about make different implementation
>
> So
>
> Tenant1 extends tenanta
>
> Tenant2 extends tenantb
>
>
> /m/
>
> -----Original Message-----
> From: Eduard Neuwirt <ed...@googlemail.com>
> Date: Fri, 15 Oct 2010 16:16:35
> To: Struts Users Mailing List<us...@struts.apache.org>
> Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
> Subject: Re: Struts, Spring, Hibernate and multiple Sessionfactories
>
> Hi Li,
>
> thanks for the answer. I didn't get how does it work within the
> struts-spring plugins ? In this case ist the the question is how to access
> to the application context directly from struts session. I could not find
> any information in the docu.
>
>
> Regards
> Eduard
>
>
>
> 2010/10/15 Li Ying <li...@gmail.com>
>
> > If you want to use multi-DB for multi-tenant (let's say tenant01 and
> > tenant02)
> >
> > I think you can create config file should likes:
> >
> > <bean id="sessionFactory_tenant01" class="xxxxx">
> >  <property name="configLocation" value="cfg_tenant01.xml"/>
> > </bean>
> >
> > <bean id="sessionFactory_tenant02" class="xxxxx">
> >  <property name="configLocation" value="cfg_tenant02.xml"/>
> > </bean>
> >
> > and then, in your java code, you can get different bean instance for
> > different tenant via [ID],
> > code looks like:
> >  BeanFactory.getBean("sessionFactory_" + tenantID,SessionFactory.class);
> >
> >
> > You can read this document for more information:
> >
> >
> http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/beans/factory/BeanFactory.html#getBean%28java.lang.String,%20java.lang.Class%29
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>

Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Frans Thamura <fr...@meruvian.org>.
How about make different implementation

So 

Tenant1 extends tenanta

Tenant2 extends tenantb


/m/

-----Original Message-----
From: Eduard Neuwirt <ed...@googlemail.com>
Date: Fri, 15 Oct 2010 16:16:35 
To: Struts Users Mailing List<us...@struts.apache.org>
Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
Subject: Re: Struts, Spring, Hibernate and multiple Sessionfactories

Hi Li,

thanks for the answer. I didn't get how does it work within the
struts-spring plugins ? In this case ist the the question is how to access
to the application context directly from struts session. I could not find
any information in the docu.


Regards
Eduard



2010/10/15 Li Ying <li...@gmail.com>

> If you want to use multi-DB for multi-tenant (let's say tenant01 and
> tenant02)
>
> I think you can create config file should likes:
>
> <bean id="sessionFactory_tenant01" class="xxxxx">
>  <property name="configLocation" value="cfg_tenant01.xml"/>
> </bean>
>
> <bean id="sessionFactory_tenant02" class="xxxxx">
>  <property name="configLocation" value="cfg_tenant02.xml"/>
> </bean>
>
> and then, in your java code, you can get different bean instance for
> different tenant via [ID],
> code looks like:
>  BeanFactory.getBean("sessionFactory_" + tenantID,SessionFactory.class);
>
>
> You can read this document for more information:
>
> http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/beans/factory/BeanFactory.html#getBean%28java.lang.String,%20java.lang.Class%29
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Li Ying <li...@gmail.com>.
I think i don't understand what you want exactly.
Can you tell me what you want to achieve?
And what your code looks like?



2010/10/15 Eduard Neuwirt <ed...@googlemail.com>:
> Hi Li,
>
> thanks for the answer. I didn't get how does it work within the
>  ? In this case ist the the question is how to access
> to the application context directly from struts session. I could not find
> any information in the docu.
>
>
> Regards
> Eduard
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Eduard Neuwirt <ed...@googlemail.com>.
Hi Li,

thanks for the answer. I didn't get how does it work within the
struts-spring plugins ? In this case ist the the question is how to access
to the application context directly from struts session. I could not find
any information in the docu.


Regards
Eduard



2010/10/15 Li Ying <li...@gmail.com>

> If you want to use multi-DB for multi-tenant (let's say tenant01 and
> tenant02)
>
> I think you can create config file should likes:
>
> <bean id="sessionFactory_tenant01" class="xxxxx">
>  <property name="configLocation" value="cfg_tenant01.xml"/>
> </bean>
>
> <bean id="sessionFactory_tenant02" class="xxxxx">
>  <property name="configLocation" value="cfg_tenant02.xml"/>
> </bean>
>
> and then, in your java code, you can get different bean instance for
> different tenant via [ID],
> code looks like:
>  BeanFactory.getBean("sessionFactory_" + tenantID,SessionFactory.class);
>
>
> You can read this document for more information:
>
> http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/beans/factory/BeanFactory.html#getBean%28java.lang.String,%20java.lang.Class%29
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Li Ying <li...@gmail.com>.
If you want to use multi-DB for multi-tenant (let's say tenant01 and tenant02)

I think you can create config file should likes:

<bean id="sessionFactory_tenant01" class="xxxxx">
  <property name="configLocation" value="cfg_tenant01.xml"/>
</bean>

<bean id="sessionFactory_tenant02" class="xxxxx">
  <property name="configLocation" value="cfg_tenant02.xml"/>
</bean>

and then, in your java code, you can get different bean instance for
different tenant via [ID],
code looks like:
  BeanFactory.getBean("sessionFactory_" + tenantID,SessionFactory.class);


You can read this document for more information:
http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/beans/factory/BeanFactory.html#getBean%28java.lang.String,%20java.lang.Class%29

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Li Ying <li...@gmail.com>.
We developed a multi-tenant app last year.

But we didn't separate their data into different DB.

Instead, we stored all data in one DB, and add
a [tenant_id] column to all tables to distinguish
which tenant it belong.

I think this is a simpler solution.

When you need to add new tenant,
you can simply add new records to one DB,
you don't have to create new DB and configure it in your executive environment.

And, when you change your DB design,
you don't have to do this in all the DBs.




2010/10/15 Eduard Neuwirt <ed...@googlemail.com>:
> Hello,
>
> I am looking for an elegant solution for the following situation.
>
> I have a multitenant struts/spring/hibernate application. Every tenant is
> stored in own database within the same RDBMS. All databases has the same
> schema. At the spring layer every tenant is represented as a datasource.
> Because I use the Hibernate I have to create multiple SessionFactories to
>
> How can I provide the correct Seesionfactory to the UserSession in struts.
> Once I have is the tenantId stored in UserSession itself.
>
> Please help
> Eduard

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Brian Thompson <el...@gmail.com>.
On Fri, Oct 15, 2010 at 11:43 AM, Dave Newton <da...@gmail.com> wrote:
> On Fri, Oct 15, 2010 at 12:39 PM, Brian Thompson <el...@gmail.com> wrote:
>>> Ever had a client that wanted/required their data segregated from
>>> everybody else's (this is not uncommon at all)? Ever wanted to
>> Apparently, it is uncommon.  I've never encountered such a demand.
>
> That... makes it uncommon?!


Oh, right.  That doesn't make it uncommon, that makes it almost unheard of.

(TBF, we're both speaking from biased samples -- but really, whether
data segregation is common or not is beside the point.)

>
>>> restrict tool access to data without jumping through any hoops
>>> ("here's the DB, here's your username/password, here's your data, and
>>> nobody else's")?
>> I haven't been in this type of situation, either.  Projects I've
>> worked on have always had user-friendly reports on the data, and what
>> little we host for people hasn't called for constantly available
>> direct DB access.
>
> I work for companies with thousands of clients: there's no "little" we
> host for people, only "a lot".
>
> Dave


Most of our projects are deployed on a client's servers rather than
hosted internally.  No big deal, just a different project environment.

-Brian

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Dave Newton <da...@gmail.com>.
On Fri, Oct 15, 2010 at 12:39 PM, Brian Thompson <el...@gmail.com> wrote:
>> Ever had a client that wanted/required their data segregated from
>> everybody else's (this is not uncommon at all)? Ever wanted to
> Apparently, it is uncommon.  I've never encountered such a demand.

That... makes it uncommon?!

>> restrict tool access to data without jumping through any hoops
>> ("here's the DB, here's your username/password, here's your data, and
>> nobody else's")?
> I haven't been in this type of situation, either.  Projects I've
> worked on have always had user-friendly reports on the data, and what
> little we host for people hasn't called for constantly available
> direct DB access.

I work for companies with thousands of clients: there's no "little" we
host for people, only "a lot".

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Brian Thompson <el...@gmail.com>.
On Fri, Oct 15, 2010 at 10:22 AM, Dave Newton <da...@gmail.com> wrote:
>> I'm not sure what reasons there would be to have it make sense
>> to store each entity in its own identically-structured DB.
>
> Ever had a client that wanted/required their data segregated from
> everybody else's (this is not uncommon at all)? Ever wanted to


Apparently, it is uncommon.  I've never encountered such a demand.


> restrict tool access to data without jumping through any hoops
> ("here's the DB, here's your username/password, here's your data, and
> nobody else's")?


I haven't been in this type of situation, either.  Projects I've
worked on have always had user-friendly reports on the data, and what
little we host for people hasn't called for constantly available
direct DB access.

That said, I do appreciate seeing a couple of these reasons; after all
it *is* always helpful to get some perspective outside my own
experience.

-Brian

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Dave Newton <da...@gmail.com>.
> I'm not sure what reasons there would be to have it make sense
> to store each entity in its own identically-structured DB.

Ever had a client that wanted/required their data segregated from
everybody else's (this is not uncommon at all)? Ever wanted to
restrict tool access to data without jumping through any hoops
("here's the DB, here's your username/password, here's your data, and
nobody else's")?

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Brian Thompson <el...@gmail.com>.
On Fri, Oct 15, 2010 at 9:45 AM, Dave Newton <da...@gmail.com> wrote:
> That's really difficult to read.


Agreed.  More whitespace would be nice, Martin.


>
> On Fri, Oct 15, 2010 at 10:38 AM, Martin Gainty wrote:
>> a database schema represents the entire structure (tables and relationships of
>> those tables) of the there is no need for multiple databases when your database
>> schema contains the persisted entities (tables)
>
> That's not necessarily true. Depending on how the database is
> accessed, structured, distributed, etc. there are several reasons why
> it may make sense to have each tenet in their own database.


Tenet?

I'd agree with Martin on this one -- it makes more sense to use one
database and store multiple entities in it than to make one DB per
entity.  I'm not sure what reasons there would be to have it make
sense to store each entity in its own identically-structured DB.

-Brian

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Dave Newton <da...@gmail.com>.
That's really difficult to read.

On Fri, Oct 15, 2010 at 10:38 AM, Martin Gainty wrote:
> a database schema represents the entire structure (tables and relationships of
> those tables) of the there is no need for multiple databases when your database
> schema contains the persisted entities (tables)

That's not necessarily true. Depending on how the database is
accessed, structured, distributed, etc. there are several reasons why
it may make sense to have each tenet in their own database.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: Struts, Spring, Hibernate and multiple Sessionfactories

Posted by Martin Gainty <mg...@hotmail.com>.





> Date: Fri, 15 Oct 2010 14:50:17 +0200
> Subject: Struts, Spring, Hibernate and multiple Sessionfactories
> From: eduard.neuwirt@googlemail.com
> To: user@struts.apache.org
> 
> Hello,
> 
> I am looking for an elegant solution for the following situation.
> 
> I have a multitenant struts/spring/hibernate application. Every tenant is
> stored in own database within the same RDBMS. All databases has the same
> schema. 
MG>a database schema represents the entire structure (tables and relationships of those tables) of the Database
MG>there is no need for multiple databases when your database schema contains the persisted entities (tables)

At the spring layer every tenant is represented as a datasource.
MG>perhaps there is some confusion as to the meaning of the term datasource ?
MG>In hibernate a datasource is the URL string which provides connection attributes to your database e.g.
MG>Configuration.setProperty("hibernate.connection.datasource", "java:comp/env/jdbc/test")

> Because I use the Hibernate I have to create multiple SessionFactories to
MG> Hibernate SessionFactory Documentation
MG>Usually an application will create
 * a single <tt>Configuration</tt>,
 * build a single instance of<tt>SessionFactory</tt> 
 * and then instantiate <tt>Session</tt>s in threads servicing client requests. 
 * The <tt>Configuration</tt> is meant
 * only as an initialization-time object. 
 * <tt>SessionFactory</tt>s are
 * immutable and do not retain any association back to the
 * <tt>Configuration</tt>.<br>
 * <br>
 * A new <tt>Configuration</tt> will use the properties specified in
 * <tt>hibernate.properties</tt> by default.
MG> Configuration->SessionFactory->1..n->Session
MG>using Hibernate as your implementing template and assuming you have a valid java.sql.Connection all you have to do is create
MG>an EmptyInterceptor object constructed from the parameters of the available UserSession
MG>then call SessionFactory.openSession to obtain the session
    /**
     * Open a {@link Session}, utilizing the specfied JDBC {@link Connection} and
     * specified {@link Interceptor}.
     * <p>
     * Note that the second-level cache will be disabled if you supply a JDBC
     * connection. Hibernate will not be able to track any statements you might
     * have executed in the same transaction.  Consider implementing your own
     * {@link org.hibernate.connection.ConnectionProvider} instead as a highly
     * recommended alternative.
     *
     * @param connection a connection provided by the application.
     * @param interceptor a session-scoped interceptor
     *
     * @return The created session.
     */
    public org.hibernate.classic.Session openSession(Connection connection, Interceptor interceptor);

OR in the case of Spring
public static Session getSession(SessionFactory sessionFactory, boolean allowCreate)
> 
> How can I provide the correct Seesionfactory to the UserSession in struts.
> Once I have is the tenantId stored in UserSession itself.
> 
> Please help
> Eduard