1

I need my app to talk to two different databases, which themselves are replicated(using Postgres streaming replication). The reason is that I want to have all the reads happening against one database and writes against the other.

I use hibernate in my application. Is there an out of the box way to achieve this?

-thanks

edit: And yes, please comment on whether what I am trying to achieve makes sense.

2 Answers 2

1

Hibernate supports sharding. See if it helps you: http://www.hibernate.org/subprojects/shards.html

If you are using spring then I know there is a way to dynamically switch the DataSource. Find more information here

This is a similar question from stackoverflow: Handling Multiple databases with NHibernate in a single application

Also same kind of question in other forum discussion: http://forum.springsource.org/showthread.php?t=12665

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

1 Comment

yes we do use spring. This is interesting, let me explore further ... thanks
0

In the past I've simply produced two session factories, and used one for read-only chunks of work and one for read-write chunks of work. I build the read-write factory, then change the configuration to have a different connection provider and add an interceptor to trap any modification attempts and build the second.

One problem with this approach is L2 cache coherence, although that's a general problem with both Hibernate caching and replicated databases.

Comments

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.