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.  [ 2 posts ] 
Author Message
 Post subject: 2 databases in hibernate
PostPosted: Tue May 09, 2006 1:28 pm 
I want to know how I can configure hibernate with 2 databases , one for reading and one for writing. Both database are same , we just want read in one database and write in other database to increase performance. Any idea how to do in hibernate ?


Top
  
 
 Post subject:
PostPosted: Tue May 09, 2006 3:09 pm 
Newbie

Joined: Fri Nov 04, 2005 11:37 am
Posts: 6
Hi,

Try following steps,

1) Create two configuration files a) ReadDB.cfg.xml b) WriteDB.cfg.xml
2) Configure both files
eg:- sessionFactory = configuration.configure( new File( dbNameWithPath+".cfg.xml") )
.buildSessionFactory()3) simply add this sesssion factoy to map used application wide
sessionFactoryMap.put(dbName,sessionFactory);

4) create two sessions in your DAO (business layer)

Session readSession=sessionFactoryUtil.getSession("readDB");
Session writeSession=sessionFactoryUtil.getSession("writeDB");

5) then read and wirte

readSession.findObject(....);
writeSession.save(.....);

Hope this helps
-Praful


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.