0

Zk and hibernate

asked 2010-10-11 03:49:06 +0800

Hebus gravatar image Hebus
78

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?

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2010-10-11 04:20:26 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

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.

link publish delete flag offensive edit

answered 2010-10-11 05:08:41 +0800

Hebus gravatar image Hebus
78

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 ?

link publish delete flag offensive edit

answered 2010-10-11 06:36:23 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

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.

link publish delete flag offensive edit

answered 2010-10-11 07:00:09 +0800

Hebus gravatar image Hebus
78

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

link publish delete flag offensive edit

answered 2010-10-11 07:47:51 +0800

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

updated 2010-10-11 07:48:26 +0800

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

link publish delete flag offensive edit

answered 2010-10-11 09:38:13 +0800

Hebus gravatar image Hebus
78

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.

link publish delete flag offensive edit

answered 2010-10-11 16:01:10 +0800

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

I mean with second project the seperation of the backend packages and classes. Sure, you can do all in one project.

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: 2010-10-11 03:49:06 +0800

Seen: 313 times

Last updated: Oct 11 '10

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