-->
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.  [ 5 posts ] 
Author Message
 Post subject: Getting a "Building new Hibernate SessionFactory"
PostPosted: Tue Jan 06, 2009 7:49 pm 
Newbie

Joined: Tue Jan 06, 2009 7:20 pm
Posts: 3
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.

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...





<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>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2009 10:44 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Spring is managing this and constructing a new SF:

2009-01-06 18:17:58,098 INFO [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] Building new Hibernate SessionFactory

Post this question on the Spring forum but before you do, check the logs and see if you're not initializing Spring over and over again. I bet that's your problem.

-Chris

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2009 11:40 am 
Newbie

Joined: Tue Jan 06, 2009 7:20 pm
Posts: 3
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() {
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2009 3:06 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
It's likely that however you're initializing Spring is wrong. Check your logs and see if Spring isn't loading many times over. Look at your code to ensure you're loading spring ONCE and letting it manage things from there. Also, there are some helpful base classes for DAO's that will avoid you having to use session factory directly (this is all in the Spring docs).

I'd suggest a read through the first couple of chapters of the Hibernate manual plus the ORM chapter of the Spring manual before you continue. Understand what each one is for before you get terribly frustrated :) Once you understand them conceptually, it will probably be obvious why your SF (and Spring context) is rebuilt many times.

-Chris

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 10:39 am 
Newbie

Joined: Tue Jan 06, 2009 7:20 pm
Posts: 3
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.