0

Mapping multiple database with Hibernate

asked 2011-10-02 08:19:04 +0800

nikoligno gravatar image nikoligno
3

Hi all!
I wrote a workaround to map multiple database with hibernate.
My modified HibernateUtil class uses a map to store all the SessionFactories, using the hibernate configuration filename as key.
The hibernate configuration filenames are set in zk.xml, as follows:

	
<preference>
 	<name>HibernateUtil.config</name>
 	<value>hibernate.cfg.xml,other.cfg.xml</value>
 </preference>

My HibernateUtil.currentSession() get the hibernate session related to first hibernate configuration file, and I provide a new HibernateUtil.currentSession(String configFile) method that gets an hibernate session related to the hibernate configuration filename "configFile".
For example, to get a session related to other.cfg.xml in the example above, you have to code something like this:

HibernateUtil.currentSession("other.cfg.xml");

Sources are here: org.alessi.zk.hibernate.zip and contains a modified version of:

HibernateSessionFactoryListener
HibernateUtil
OpenSessionInViewListener

All seems to work fine for me.

Any suggestion? Can you test it?

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2012-11-14 18:26:31 +0800

gaucho gravatar image gaucho
6

Hi nikoligno,

Thanks! I will try it and I will let you know.

Cheers,

Luis

link publish delete flag offensive edit

answered 2012-11-15 17:05:29 +0800

gaucho gravatar image gaucho
6

Hi nikoligno,

It works! Clean and simple, thank you very much!

Cheers,

Luis

link publish delete flag offensive edit

answered 2014-11-03 12:04:06 +0800

KeithK gravatar image KeithK
15

Hi, Firstly, my apologies for posting on an old thread, but I have just been asked to add exactly this functionality to an existing application. The link in the above post is now out of date so can I ask if anyone has the sources provided could they please post a new link or maybe send them to me.

Many thanks, Keith

link publish delete flag offensive edit

answered 2014-11-14 00:36:00 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2014-11-14 00:36:32 +0800

Have a look at the EmptyInterceptor class from Hibernate.

link publish delete flag offensive edit

answered 2014-11-14 08:53:21 +0800

oreszek gravatar image oreszek
1

some1 can help me with this ?

link publish delete flag offensive edit

answered 2014-11-14 10:28:30 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

updated 2014-11-14 10:29:30 +0800

I have already done this. wait until this week end, i will write down the steps in my blog.

link publish delete flag offensive edit

answered 2014-11-14 11:34:36 +0800

orebiszek gravatar image orebiszek
1
http://www.pystyportfel.p...

i need help a lot :< i cant make it through

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-10-02 08:19:04 +0800

Seen: 889 times

Last updated: Nov 14 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More