I posted this on the spring forum and I thank you for your response. I'm a newbie to spring and hibernate and am in the learning process. I was wondering what would be causing spring to reload. I have been taking a look at this post
http://forum.hibernate.org/viewtopic.php?t=960856&highlight=leaks
and also at this one
http://acs.lbl.gov/~hoschek/javatree/share/jdbc/hibernate-2.1/doc/114.html
I know that this has to do with the SessionFactory being recreated everytime on DB Access. I am wondering if this is a configruation files that is causing this
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean"
lazy-init="true">
<property name="jndiName">
<value>ABC_DS</value>
</property>
</bean>
<bean id="dataSource-p"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
lazy-init="true">
<property name="driverClassName">
<value>${db.driver}</value>
</property>
<property name="url">
<value>${db.url}</value>
</property>
<property name="username">
<value>${db.userid}</value>
</property>
<property name="password">
<value>${db.passwd}</value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="annotatedClasses">
<list>
<value>com.abc.domain.Agent</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">${db.hbm2ddl}</prop>
<prop key="hibernate.dialect">${db.dialect}</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</prop>
<prop
key="hibernate.bytecode.use_reflection_optimizer">
true
</prop>
<prop key="hibernate.connection.SetBigStringTryClob">
true
</prop>
<prop key="hibernate.jdbc.batch_size">0</prop>
<prop key="connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider
</prop>
<prop key="hibernate.c3p0.min_size">1</prop>
<prop key="hibernate.c3p0.max_size">10</prop>
<prop key="hibernate.c3p0.timeout">300</prop>
<prop key="hibernate.c3p0.validate">true</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<!--
<prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</prop>
-->
<prop key="net.sf.ehcache.configurationResourceName">
/ehcache.xml
</prop>
</props>
</property>
</bean>
<!-- Creates AOP proxies based on all candidate Advisors in the current BeanFactory. -->
<bean id="autoproxy"
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" />
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributeSource">
<bean
class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource" />
</property>
</bean>
<!-- Working in concert with the DefaultAdvisorAutoProxyCreator, creates a transaction proxy! -->
<bean id="transactionAdvisor"
class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
<property name="transactionInterceptor"
ref="transactionInterceptor" />
</bean>
<!-- Spring post processor which handles hibernate exceptions. -->
<bean
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
<bean id="agentDAO" class="com.abc.dao.AgentDAO">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="agentService" class="com.abc.service.AgentServiceImpl">
<property name="agentDAO" ref="agentDAO" />
<property name="authorizationManager"
ref="authorizationManager">
</property>
<property name="ABCAgentRegistrationImpl"
ref="agentRegistration">
</property>
</bean>
<bean id="contextSource"
class="com.abc.ABC.auth.util.ABCLdapContextSource">
<property name="url" value="${java.naming.provider.url}" />
<property name="userDn" value="${ABC.ldap.proxyuser.dn}" />
<property name="password"
value="${ABC.ldap.proxyuser.credentials}" />
</bean>
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<!-- Bean definition for Authorization Manager -->
<bean id="authorizationManager"
class="com.abc.ABC.auth.DAO.ABCAuthorizationManagerImpl">
<constructor-arg ref="flCriteria" />
<constructor-arg ref="findByFLCriteria" />
<constructor-arg ref="seIDCriteria" />
<constructor-arg ref="findBySEIDCriteria" />
<constructor-arg ref="alarmIDCriteria" />
<constructor-arg ref="customerIDCriteria" />
<constructor-arg ref="ldapTemplate" />
<constructor-arg ref="userDao" />
<constructor-arg ref="findByAlarmIDCriteria" />
<constructor-arg ref="uuidCriteria" />
<constructor-arg ref="findByUUIDCriteria" />
</bean>
<!-- Register Agents -->
<bean id="agentMapConvertor"
class="com.abc.srd.ssdp.directory.MapConvertor">
<property name="map">
<map>
<entry>
<key>
<value>objectclass</value>
</key>
<list>
<value>avSrdManagedAgent</value>
</list>
</entry>
</map>
</property>
</bean>
<bean id="agentTemplateReader"
class="com.abc.srd.ssdp.directory.TemplateReader">
<property name="mapConvertor">
<ref bean="agentMapConvertor" />
</property>
<property name="RDNPattern">
<value>solutionelementid={0},ou=Devices,o={1}</value>
</property>
</bean>
<!-- Bean definition for Agent Registration -->
<bean id="agentRegistration"
class="com.abc.ABC.auth.DAO.ABCAgentRegistrationImpl">
<constructor-arg ref="agentTemplateReader" />
<constructor-arg ref="ldapTemplate" />
<constructor-arg ref="authorizationManager" />
<constructor-arg ref="ldapBean" />
<property name="adminRDN" value="${ABC.ldap.proxyuser.dn}" />
<property name="adminPassword"
value="${ABC.ldap.proxyuser.credentials}" />
<property name="jdbcDriver"
value="${ABC.ldapManagerBean.jdbcDriver}" />
<property name="jdbcUrl" value="${ABC.ldapManagerBean.jdbcUrl}" />
<property name="baseDN" value="${ABC.ldap.base.dn}" />
<property name="providerUrl"
value="${java.naming.provider.url}" />
<property name="ldapBean">
<ref bean="ldapBean" />
</property>
</bean>
<bean id="userDao" class="com.abc.util.ABCUserFactory"
factory-method="getABCUserPstore">
</bean>
<bean id="ldapBean"
class="com.abc.srd.ssdp.saas.ejb.admin.LdapManagerBean">
</bean>
</beans>
or if I am going to have to make changes to the code.
Code:
import org.hibernate.Session;
import org.hibernate.SessionFactory;
abstract public class AbstractDAO {
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
protected Session getCurrentSession() {
return sessionFactory.getCurrentSession();
}
public AbstractDAO() {
}
}