Reputation: 97
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.
Upvotes: 1
Views: 902
Reputation: 133822
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.
Upvotes: 0
Reputation: 80192
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
Upvotes: 1