-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello all. I am writing an Open Source help desk application (http://code.google.com/p/triage/). Upon first accessing the web app, the user is going to be prompted to configure the default settings for the application. Part of this is configuring the database connection settings. Since I am using Hibernate, I need to configure the Listeners for the Hibernate session handling. I figured out that I can load Listeners at run time using "desktop.getWebApp().getConfiguration().addListener()", but for the Hibernate listeners, it searches for the Hibernate.cfg.xml file. Since I am using a programmatic configuration of Hibernate, there is no Hibernate.cfg.xml file. Can anyone give me an idea of how I can load this listener such that it doesn't look for the Hibernate config file?
Thanks,
Deven
OK, I think I have an answer. If I created my own version of the org.zkoss.zkplus.hibernate.* classes, I can extend them to detect the already initialized Hibernate session factory. I believe I will configure the application to store the SessionFactory object in the InitialContext of the application and have those classes check there for it. Does anyone have a better idea?
Woohoo! It works. You can see the changes I made to the HibernateUtil and OpenSessionInViewListener classes at:
http://code.google.com/p/triage/source/browse/#svn/trunk/Triage/src/com/blogspot/devenphillips/helpdesk/zk/hibernate%3Fstate%3Dclosed
The basic concept is that after performing a programmatic configuration of Hibernate, I store the SessionFactory object as an attribute in the WebApp. I then perform an addListener() call to add the Hibernate listeners. The modified HibernateUtil checks the WebApp object for the existence of the attribute and uses it, if it is available. I also had to make a change to OpenSessionInViewListener to handle the case that no Transactions are active at a certain point. It probably would not have caused a problem, but why clutter up the logs with unnecessary stack traces.
Asked: 2009-02-04 06:12:36 +0800
Seen: 275 times
Last updated: Feb 04 '09