Results 1 to 4 of 4

Thread: Getting multiple a "Building new Hibernate SessionFactory"

  1. #1
    Join Date
    Jan 2009
    Posts
    3

    Default Getting multiple a "Building new Hibernate SessionFactory"

    Application Server = JBOSS
    DB = Oracle Database 10g Enterprise Edition Release 10.2.0.3.0
    Dialect: Oracle9FixedSequencesDialect


    Getting this messge everytime I Acccess the DB. It cuases an increase of 1MB in PermGen Memory.

    Code:
    2009-01-06 18:17:58,098 INFO [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] Building new Hibernate SessionFactory 
    2009-01-06 18:17:58,122 WARN [org.hibernate.cfg.Environment] Property [hibernate.cglib.use_reflection_optimizer] has been renamed to [hibernate.bytecode.use_reflectio 
    n_optimizer]; update your properties appropriately 
    2009-01-06 18:17:58,122 INFO [org.hibernate.connection.ConnectionProviderFactory] Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSource 
    ConnectionProvider 
    2009-01-06 18:17:58,122 INFO [org.hibernate.cfg.SettingsFactory] RDBMS: Oracle, version: Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production 
    With the Partitioning, OLAP and Data Mining options

    Thanks for your Help in Advance...




    Code:
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
    <property name="dataSource"> 
    <ref bean="dataSource" /> 
    </property> 
    <property name="annotatedClasses"> 
    <list> 
    <value>.....</value> 
    <value>.....</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="net.sf.ehcache.configurationResourceName"> 
    /ehcache.xml 
    </prop> 
    </props> 
    </property> 
    </bean>

  2. #2
    Join Date
    Jan 2009
    Posts
    3

    Default

    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...ighlight=leaks

    and also at this one

    http://acs.lbl.gov/~hoschek/javatree...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() {
    	}
    }

  3. #3
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    How do you load the application context?

  4. #4
    Join Date
    Jan 2009
    Posts
    3

    Default

    I just noticed that the Application Context is be created each time the Object is used. Thanks for the advice. Once I created a singleton for the Appplication context my problem went away.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •