carlos7gl
Apr 1st, 2009, 04:55 AM
Hi:
I'm having problems with database connections in my web application. I'm using a Spring + JPA + Hibernate (as JPA provider) configuration.
The problem is that when a transactional method is invoked during the http request processing (the method is annotated with @Transactional), the connection seems to remain opened when the request processing finish. As a consequence, when the number of http requests gets larger than the maximum number of active connections configured in the pool, the application does not work, because there aren't available connections to the database.
So what I need is to guarantee that all database connections (i.e, Hibernate Sessions) get closed when the http request processing has finished. Please see configuration details below.
Thank you very much for your help.
This is the transactional method:
@Transactional(readOnly = true)
public List<ExpedienteListadoDto> obtenerListadoTareas(String codUsuario, int offset, int tamanioPagina, List<PerfilDto> perfiles) {...}
We are injecting the EntityManager in all our DAOs (used internally by the transactional method), as follows:
@PersistenceContext
private EntityManager entityManager;
And this is the JPA configuration in the spring configuration file:
<context:annotation-config />
<tx:annotation-driven transaction-manager="txManager" />
<context:component-scan base-package="*" />
<bean id="entityManagerFactoryBean"
class="org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVen dorAdapter">
<property name="showSql" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.OracleDialect" />
</bean>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory"
ref="entityManagerFactoryBean" />
</bean>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver" />
<property name="url"
value="jdbc:oracle:thin:@10.1.24.17:1521:DMAP1" />
<property name="username" value="EXPCONV" />
<property name="password" value="EXPCONV" />
<property name="maxActive" value="20" />
<property name="minIdle" value="0" />
<property name="maxIdle" value="-1" />
<property name="maxWait" value="50000" />
<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="10" />
</bean>
I'm having problems with database connections in my web application. I'm using a Spring + JPA + Hibernate (as JPA provider) configuration.
The problem is that when a transactional method is invoked during the http request processing (the method is annotated with @Transactional), the connection seems to remain opened when the request processing finish. As a consequence, when the number of http requests gets larger than the maximum number of active connections configured in the pool, the application does not work, because there aren't available connections to the database.
So what I need is to guarantee that all database connections (i.e, Hibernate Sessions) get closed when the http request processing has finished. Please see configuration details below.
Thank you very much for your help.
This is the transactional method:
@Transactional(readOnly = true)
public List<ExpedienteListadoDto> obtenerListadoTareas(String codUsuario, int offset, int tamanioPagina, List<PerfilDto> perfiles) {...}
We are injecting the EntityManager in all our DAOs (used internally by the transactional method), as follows:
@PersistenceContext
private EntityManager entityManager;
And this is the JPA configuration in the spring configuration file:
<context:annotation-config />
<tx:annotation-driven transaction-manager="txManager" />
<context:component-scan base-package="*" />
<bean id="entityManagerFactoryBean"
class="org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVen dorAdapter">
<property name="showSql" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.OracleDialect" />
</bean>
</property>
</bean>
<bean id="txManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory"
ref="entityManagerFactoryBean" />
</bean>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver" />
<property name="url"
value="jdbc:oracle:thin:@10.1.24.17:1521:DMAP1" />
<property name="username" value="EXPCONV" />
<property name="password" value="EXPCONV" />
<property name="maxActive" value="20" />
<property name="minIdle" value="0" />
<property name="maxIdle" value="-1" />
<property name="maxWait" value="50000" />
<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="10" />
</bean>