-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
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
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
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
Asked: 2007-01-08 17:07:29 +0800
Seen: 200 times
Last updated: Jan 10 '07