-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Connection Pooling
PostPosted: Mon Jul 23, 2007 7:26 am 
Newbie

Joined: Mon Jul 23, 2007 7:14 am
Posts: 1
Hi All,

Can anyone help me as to how Hibernate classes internally read the DBCP properties for Connection Pooling? How hibernate takes care to limit the maximum number of active connections at any given time?

Looking forward for your immediate help.


Top
 Profile  
 
 Post subject: DBCP configuration
PostPosted: Mon Jul 23, 2007 10:48 am 
Beginner
Beginner

Joined: Wed Oct 25, 2006 9:05 am
Posts: 40
Location: France, Lieusaint
If you use Spring, which is a good idea, here is the way Hibernate is feeded with dbcp source info.

First a dataSource is created in the config.xml file of Spring:



Code:
   <bean id="dbcpDataSource"
      class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
      lazy-init="true">
      <property name="driverClassName">
         <value>${jdbc.driverClassName}</value>
      </property>
      <property name="url">
         <value>${jdbc.url}</value>
      </property>
      <property name="username">
         <value>${jdbc.username}</value>
      </property>
      <property name="password">
         <value>${jdbc.password}</value>
      </property>
      <property name="removeAbandoned">
         <value>true</value>
      </property>
      <property name="removeAbandonedTimeout">
         <value>30</value>
      </property>
      <property name="minIdle">
         <value>3</value>
      </property>
      <property name="initialSize">
         <value>1</value>
      </property>
      <property name="maxActive">
         <value>40</value>
      </property>
      <property name="maxWait">
         <value>5000</value>
      </property>
   </bean>



Then this pool is injected in the HibernateSessionFactory :

Code:
   <bean id="transactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager"
      lazy-init="true">
      <property name="sessionFactory">
         <ref local="hibernateSessionFactory" />
      </property>
      <property name="dataSource">
         <ref bean="dbcpDataSource" />
      </property>
   </bean>


so that now, HIbernate knows WHERE to get a connection from the pool.

You see in this code how you can tune your pool for optimization.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.