-->
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.  [ 3 posts ] 
Author Message
 Post subject: Issue while creating hibernate session factory
PostPosted: Thu Sep 26, 2013 8:03 am 
Newbie

Joined: Thu Sep 26, 2013 7:31 am
Posts: 3
Hello ,

My application is designed with Spring MVC , hibernate and SQL Server 2008.

So here issue we are facing is when ever the page get loaded(fetching the data from DB) , It is freezing at the below point for 10-20 seconds(When the sessionfactory is created for first time)

SessionFactory factory= HibernateUtil.getSessionFactory();

Pasting my hibernate.cfg .xml and .java below


Code:
<hibernate-configuration>
    <session-factory>        <!-- Database connection settings -->
     <property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
        <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
       <property name="connection.url">************</property>
        <property name="connection.username">*******</property>
        <property name="connection.password">******</property>       <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">20</property>        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.SQLServer2008Dialect</property>        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>        <!-- Disable the second-level cache -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>       
        <property name="hbm2ddl.auto">validate</property>
        <mapping class="com.**********************"/>
        <mapping class="com.**********************"/>
        <mapping class="com.**********************"/>
         <mapping class="com.**********************"/>
         <mapping class="com.**********************"/>
         <mapping class="com.**********************"/>
       </session-factory>
</hibernate-configuration>


HibernateUtil.java
Code:
public class HibernateUtil {
   
   static SessionFactory factory;
      
      static{
         Configuration cfg = new Configuration();
         factory = cfg.configure().buildSessionFactory();
      }
      
      public static SessionFactory getSessionFactory(){
         return factory;
      }

}


Any guidance to resolve this issue is appreciated.

Note : We are using entity classes instead of xml

Thanks in advance ,
Anish


Top
 Profile  
 
 Post subject: Re: Issue while creating hibernate session factory
PostPosted: Thu Sep 26, 2013 12:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 18, 2012 5:03 am
Posts: 36
Location: Fort Wayne, Indiana, USA
If you're using Spring MVC, it would be far better to add sessionFactory and transactionManager beans to your servlet context, then @Autowire those into your app using a typical Controller -> Service -> DAO setup. That will initialize the SessionFactory when your app starts up in the application server, rather than when a page is loaded for the first time. Try googling "spring mvc hibernate dao" for several decent examples.


Top
 Profile  
 
 Post subject: Re: Issue while creating hibernate session factory
PostPosted: Fri Nov 08, 2013 4:41 am 
Newbie

Joined: Thu Sep 26, 2013 7:31 am
Posts: 3
thanks a lot brmeyer :)


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