4

My app currently handles its users in its own db. I'm in the process of creating a CAS app that will centralize the managing of users for my app and others. This CAS app will use a db of its own and the other apps will have access to it. I use the same hibernate entity "User" for all the apps including the CAS.

My goal is to be able to configure whether an app will use the "local" db or the "cas" db when looking for the "User" entity.

This configuration doesn't have to be changed at run time. it can be a spring context xml config (or just a different set of imports).

I don't want to use additional session factories. I tried to walk down that road and got stuck once I realized I would need to define more open-in-session-view filters in the web.xml - one per factory.

How can I configure the single session factory to load this Entity (and maybe some other related ones) from a different data source based on some configuration?

2 Answers 2

1

Have you looked at the multi-tenant support in Hibernate 4? http://relation.to/Bloggers/MultitenancyInHibernate

Sign up to request clarification or add additional context in comments.

6 Comments

I looked at it just now. The first example about partitioning would solve this problem. This lead me to look at hibernate shards and this in turn lead me to a dead end. it looks like hibernate shards is somewhat dead. I can't find the project on any maven repo (tried central and jboss). I can't even find its classes in Jarvana. It's only downloadable from hibernate.org site but I don't want to mess with maven local repo jar installations... I'll try and take a look at their second suggestion - hibernate filter.
I'm using hibernate 3.6.1-Final by the way.
multitenancy != shards. It's a new feature introduced in Hibernate 4. So if you're not able to upgrade, then disregard this. It's the "proper" way to handle multiple datasources in Hibernate nowadays though.
I'm updating to 4.1.0.Final atm. will see if it breaks anything in my project. Anyway, my problem is not a real multi-tenancy problem. I don't have multiple tenants that need their data loaded from different sources. I only need to load my user entity from a different db. I figured sharding would work because I would configure the users db as a shard - when using cas the whole shard would be the cas db, when not using it the whole shard would be the app local db.
Finished migrating to 4.1.0. I looked at the connection provider solution but its basically the same as Spring's AbstractRoutingDataSource. I need to access the CAS db only for user entities, not for all. It looks like its back to 2 session factories or using plain old jdbc+sql...
|
0

Take a look at this blog post about dynamic datasource routing. It may help you :-)

1 Comment

Already looked at this one and figured that it doesn't help me. In their example they load Items(Or users...) from different db's according to some config. I have more data except users, and I don't want to route the loading of that data to a different datasource/db. I only want users to load from a different db according to some config.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.