-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I am using ZK and Hibernate. Till now everything is good.
But for my project, I have to communicate with two distinct databases.
How can I manage this? I have created a second hibernate configuration file, created my mapping classes, as I was doing for the first database. But the connection to the second database never happens.
Any hint to do this?
Hi Hebus,
I believe you would get more accurate information about this on hibernate forums but my guess is you need to create 2 different hibernate sessions connecting with your 2 distinct databases. Something on this line
Configuration c1 =new AnnotationConfiguration().configure("db1.cfg.xml") Configuration c2= new AnnotationConfiguration().configure("db2.cfg.xml") sessionfactory1 = c1.buildSessionFactory(); sessionfactory2 = c2.buildSessionFactory();
Better check with Hibernate documentation.
Sure the better way, as hibernate forums says, it is to have two different configuration files, using two different sessions.
But the point is that I have no access to the Session Factory as it is include in the zk.xml.
<!-- Hibernate SessionFactory lifecycle --> <listener> <description>Hibernate SessionFactory lifecycle</description> <listener-class> org.zkoss.zkplus.hibernate.HibernateSessionFactoryListener </listener-class> </listener> <!-- Hibernate OpenSessionInView Pattern --> <listener> <description>Hibernate Open Session In View life-cycle </description> <listener-class>org.zkoss.zkplus.hibernate.OpenSessionInViewListener </listener-class> </listener> <!-- Hibernate thread session context handler --> <listener> <description>Hibernate thread session context handler </description> <listener-class> org.zkoss.zkplus.hibernate.HibernateSessionContextListener </listener-class> </listener>
With this definition, I have not a Session Factory class. So I am not able to create a specific session.
Is there a way to override this ?
Hi Hebus,
Ok it wasn't clear from your first post that you were using zkplus hibernate support.
Currently it is not possible to achieve this and you probably will have to write your own hibernate session utility for this. If time permits I'll work on a sample for you.
Hi Ashishd,
Thanks for your reply.
Sure it will be a good help to view an example on how to use ZK and hibernate without zkplus hibernate support.
For now, I do not know how I can achieve this.
May be as an improvement for zkplus hibernate support, it will be useful to have an optional line in the zk.xml for indicating the configuration file.
Nevertheless, I am looking forward an example if you have time
Regards
Hi Hebus,
you can have a look on the configuration files in the Zksample2 demo application. It works in these way.
So it's easy to extend/duplicate/modify it to connect to a second database.
The best way for this is do the whole stuff for the second database in a seperate project.
best
Stephan
Hi Terry,
Sure I will look the zksample2. But I really prefer not having a second project to handle my specific case.
The best for me is to have one single project, with multiple database connection. In fact, I have to aggregate multiple data from multiple database.
And I have to publish data from one database to another database. So doing a second project is not a good solution for me.
I mean with second project the seperation of the backend packages and classes. Sure, you can do all in one project.
Asked: 2010-10-11 03:49:06 +0800
Seen: 313 times
Last updated: Oct 11 '10