java - How to handle Connection pool size established by EntityManger through a Spring Application -


we have web application implementing spring mvc 3.2 using jpa framework orm. problem entitymanager creating lot of open connections database. want handle in such way every query connection should established , closed after completion.

as per spring implementation entitymanager created once. problem here in way want handle client connections entitymanager creating querying database.

whenever query completed in database, connection goes sleep, instead want close once query returns result.

db type: mysql

my configuration jpa :

<tx:annotation-driven transaction-manager="transactionmanager" /> <bean id="transactionmanager" class="org.springframework.orm.jpa.jpatransactionmanager">     <property name="entitymanagerfactory" ref="entitymanagerfactory" /> </bean> <bean class="org.springframework.orm.jpa.support.persistenceannotationbeanpostprocessor" />  <bean id="entitymanagerfactory"     class="org.springframework.orm.jpa.localcontainerentitymanagerfactorybean">     <property name="packagestoscan" value="com.reppify" />     <property name="jpapropertymap" ref="jpapropertymap" />     <property name="datasource" ref="datasourcelocal" />     <property name="persistenceunitname" value="cron-jpa" />     <property name="jpavendoradapter">         <bean class="org.springframework.orm.jpa.vendor.hibernatejpavendoradapter" />     </property> </bean>  <bean id="datasourcelocal"     class="org.springframework.jdbc.datasource.drivermanagerdatasource">     <property name="driverclassname" value="${database.driver}" />     <property name="url" value="${database.url}" />     <property name="username" value="${database.user}" />     <property name="password" value="${database.password}" /> </bean>   

we using hibernate-jpa-api-2.0 jar dependency project.
, java base dao implementation injecting entitymanager looks like:

protected entitymanager entitymanager;

@persistencecontext public void setentitymanager(entitymanager entitymanager) {     this.entitymanager = entitymanager; } 

please suggest optimum solution same.

drivermanagerdatasource not connections pool, creates new connection on every call. class useful testing shouldn't use in production, choose connection pool instead. there many connection pools choose from:


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -