-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: sessionFactory.openSession(Connection) and N sess factories.
PostPosted: Fri Nov 19, 2004 1:09 pm 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
I've seen in other posts Gavin suggesting use of a single session factory when connecting to multiple datasources sharing the same schema and domain model.

We provide the connection to our session factories openSession method in a thread local at the start of a transaction. The implications we see are:

- limited to working with one datasource per tx since 1st level cache may be invalid (i.e. two entities with the same id are accessed in a single tx).
- 2nd level cache not applicable, would introduce invalid data. Limited to transaction level cache.

Are there any other caveats?

Roll


Top
 Profile  
 
 Post subject: Bump.
PostPosted: Thu Mar 03, 2005 12:25 pm 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
Hi,

Apologies for bumping this post, however, I'd love to hear some reaction from the Hibernate team.

This is a topic of heated debate in my organization as we've got to address this in a coming iteration.

Thanks,
Roll


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 09, 2005 2:03 pm 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
No thoughts?

This is what we decided to do:

We're going with multiple session factories. Although it is slightly more to maintain (multiple mbean services in JBoss + multiple data sources) and we currently don't see any benefit in our application of 2nd level cache, we don't want to constrain ourselves to not having the cache in the future. Most of our entities are highly transactional (lots of reads and writes) and very few read-only entities.

On an interesting side note: we're passing the session factory name in a custom JAAS login module that connects to the correct factory upon authentication. The correct session factory is then used for the duration of that principles session until he logs out.

Any comments welcome...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 10, 2005 10:42 am 
Newbie

Joined: Tue Mar 08, 2005 11:29 am
Posts: 14
I'm on a project with similar requirements (i.e. the user will log in and basically select the database they need to work with - same schema and domain model) to your's. We've got the added complication of using Spring on top of Hibernate.

Just curious how you're making the correct SessionFactory apply for the length of a principal's HTTP session?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 10, 2005 11:02 am 
Regular
Regular

Joined: Tue Dec 09, 2003 2:39 pm
Posts: 106
Location: Toronto, Canada
We're using JBoss as our EJB container. I'm assuming you're using Spring but not using EJBs, right?

In any case, what we do is authenticate our user's via JAAS and put the session factory name in a custom principal and stuff it into the session context. Whenever a user makes a subsequent invocation to the middle-tier the principal will be available to the user's session context. When we prepare a session, we pull out the session factory name from the principal in the session context, and use it to retrieve the correct session factory for each transaction.

We use the transaction-per-request model.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 10, 2005 3:30 pm 
Newbie

Joined: Tue Mar 08, 2005 11:29 am
Posts: 14
I understand. You're right in that we're not using EJBs. :)

I think we'll end up stuffing the user's selection into a HTTP Session attribute and use a Servlet Filter to place that value (and clean it up after the request) into a ThreadLocal. That way we don't have to pass around that info through the tiers and can use that for the basis of the selection.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.