0

OpenSessionInViewFilter

asked 2007-04-27 17:20:39 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4284518

By: taskoba

After 15 days tring to understand and solve a LazyInitialization problem, i started to think that i should show the problem and the solution to the communit.

The catch:
I work in application witch access two databases. And i use hibernate+spring+acegi+ZK.

All the configuration needed to make the hibernate session open in presentation layer (ZK) were made, and are showed in http://www.zkoss.org/smalltalks/hibnsprn/hibn_sprn_zk.html.

But in no place is showed how we handle multiple SessionFactories, witch are necessary for multiple DB's the solution is to add on the web.xml the follow
configuration:

<filter>
<filter-name>{Your Filter Name}</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilt
er</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>{Your Session Factory Bean Name}</param-value>
</init-param>
</filter>

</filter-mapping>
<filter-mapping>
<filter-name>{Your Filter Name}</filter-name>
<url-pattern>{Your URL pattern needed to be "watched"}</url-pattern> </filter-mapping>

The above configuration is needed for each SessionFactory bean created.

This topic is doesn't apply only to ZK but to any presentation framework, but ZK is my favorite!

I hope that helps and save your time finding the solution.

Best Regards

taskoba


delete flag offensive retag edit

6 Replies

Sort by ยป oldest newest

answered 2007-04-30 09:59:12 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4287399

By: henrichen

Hi taskoba,

Can you write the above to ZK's How-Tos. I am afraid that your contribution will be buried in this "forum sea" some days after :-).

http://en.wikibooks.org/wiki/ZK/How-Tos

/henri


link publish delete flag offensive edit

answered 2009-06-02 12:15:50 +0800

hkn gravatar image hkn
246 3

Hello all,

I picked up this old thread. I started to work with hibernate for a while and as far as I just use one single database (==> just one hibernate.cfg.xml) the zkplus concept concept works fine .

Now I have a more complex situation and I have to access 4 different databases which means 4 hibernate???.cfg.xml files.

I have looked into the src of org.zkoss.zkplus.hibernate.HibernateUtil. It is possible to address a different file instead of hibernate.cfg.xml but I found no hint how to handle more then one hibernate.cfg.xml.

I hope someone else has solved that problem before !

BtW. I am NOT using spring, so any hint about zk + spring + hibernate will not fit.


Many thanks in advance!

Horst

link publish delete flag offensive edit

answered 2009-06-03 11:05:58 +0800

dennis gravatar image dennis
3669 1 6
http://www.javaworld.com....

Horst,
you can set the configuration file to any location , check this http://www.zkoss.org/javadoc/3.6.1/zk/org/zkoss/zkplus/hibernate/HibernateUtil.html
however I don't think hibernate.cfg.xml accepts more than 1 sessionFactory,
(search 'multiple sessionFactory hibernate.cfg.xml example' on google , you will find this)
and there is no multiple session factory concept in HibernateUtil.
so, if you don't want to write any custom code ,then you have no way to do this.
please post this to feature request , :D

link publish delete flag offensive edit

answered 2009-06-08 09:37:33 +0800

hkn gravatar image hkn
246 3

Hi Dennis!
As I expected this answer after investigating the zkplus/hibernate/*.java sources and so I started to rewrite it :-(.

I will make my changes public here as soon as I am sure that it is stable, I think there will be more zk users who may run into the same trouble.

Kind regards
Horst

link publish delete flag offensive edit

answered 2009-06-08 10:23:28 +0800

dennis gravatar image dennis
3669 1 6
http://www.javaworld.com....

Horst,
I am very glad to see this contribution.
how about write a small talk (wiki)for it?
:)

link publish delete flag offensive edit

answered 2009-06-08 11:20:57 +0800

hkn gravatar image hkn
246 3

Well, writing as smalltalk is always a matter of time :-(
... I will try ...

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: 2007-04-27 17:20:39 +0800

Seen: 471 times

Last updated: Jun 08 '09

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