0

Hibernate + Spring connection problem

asked 2007-01-08 17:07:29 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


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

By: matteo_barbieri

Hi,
I've a problem using Hibernate and Spring (and, of course, ZK).
I make some query using hibernate, and after those queries are executed, all connections are still open.
In a short time max_connections is reached and the program got an exception
(org.hibernate.exception.JDBCConnectionException: Cannot open connection).
I read all Smalltalks, but I think I missed some configuration...
This is my zk.xml:

<zk>
<listener>
<description>Spring TransactionSynchronizationManager handler</description>
<listener-class>org.zkoss.zkplus.spring.SpringTransactionSynchronizationList
ener</listener-class>
</listener>
</zk>

And my applicationContext.xml:

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
destroy-method="close">
... database settings ...
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingResources">
... resource files ...
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLInnoDBDialect
</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</prop>
</props>
</property>

It seems that connection are not closed after query execution... Must I add other configurations in zk.xml?

Please help :(

Thank you,
bye


delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2007-01-09 01:13:51 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


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

By: henrichen

Did you set the Spring's OpenSessionInViewFilter in web.xml? This is the configuration of session-per-request which will open and close your connection automatically (in the filter).

In ZK + Spring + Hibernate, the Hibernate is really controlled by Spring. I mean ZK does not control the life cycle of the Hibernate session directly. Rather, it is controlled by Spring.

/henri

link publish delete flag offensive edit

answered 2007-01-09 09:22:59 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


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

By: matteo_barbieri

Ok, I added this to my web.xml:

<!-- Hibernate OpenSession Filter -->
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sessionFactory</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*.zul</url-pattern>
</filter-mapping>

and now it seems to work, but every time I make a query a lot of connections are opened, then some of them are closed, is it correct?

Thanks

link publish delete flag offensive edit

answered 2007-01-10 04:06:56 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


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

By: henrichen

For an OpenSessionInViewFilter, it opens the Hibernate session for EACH request then close it when the request response back.

/henri

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-01-08 17:07:29 +0800

Seen: 200 times

Last updated: Jan 10 '07

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