2017-10-24 5 views
1

私はhibernateを使用してmavenアプリケーション開発を行っています。セッションファクトリの作成に初めてロードするのに多くの時間がかかります

セッションファクトリを初めてロードする際に、セッションファクトリのロードに時間がかかります(約3〜4分)が、その後のセッションファクトリの作成は瞬時に行われます。タイムラグを減らすために私がどのような変更を加えるべきかを理解するのに助けてくれる人はいますか?ここで

は、Hibernateユーティリティファイルです:

package com.infosys.common.util; 

import java.util.logging.Logger; 

import org.hibernate.SessionFactory; 
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 
import org.hibernate.cfg.Configuration; 
import org.hibernate.service.ServiceRegistry; 

/*import org.hibernate.SessionFactory; 
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 
import org.hibernate.cfg.Configuration; 
import org.hibernate.service.ServiceRegistry;*/ 

// TODO: Auto-generated Javadoc 
/** 
* The Class HibernateUtilities. 
*/ 
public class HibernateUtilities { 

    /** The Constant CONFIGURATION_LOCATION. */ 
    private static final String CONFIGURATION_LOCATION = "com/infosys/common/util/hibernate.cfg.xml"; 
    private static final Logger LOGGER = Logger.getLogger(HibernateUtilities.class.getName()); 

    /** The session factory. */ 
    private static SessionFactory sessionFactory = null; 

    /** The service registry. */ 
    private static ServiceRegistry serviceRegistry; 

    /** 
    * Gets the session factory. 
    * 
    * @return the session factory 
    */ 
    public static SessionFactory getSessionFactory() { 
     return sessionFactory; 
    } 

    /** 
    * Creates the session factory. 
    * 
    * @return the session factory 
    * @throws Exception 
    *    the exception 
    */ 
    public synchronized static SessionFactory createSessionFactory() throws Exception { 
     if (sessionFactory == null) 
     { 
      try { 
       LOGGER.info("Logger Name: " + LOGGER.getName()); 

       // Step1 : Loading the configuration details from 
       // hibernate.cfg.xml 

       Configuration configuration = new Configuration().configure(CONFIGURATION_LOCATION); 
       configuration. 
      setProperty("hibernate.temp.use_jdbc_metadata_defaults","false"); 

       // Step2 : Creating ServiceRegistry using the 
       // StandardServiceRegistryBuilder and Configuration defined in 
       // Step 1 
       serviceRegistry = new StandardServiceRegistryBuilder().configure(CONFIGURATION_LOCATION).build(); 

       // Step3 : Creating the SessionFactory using the Configuration 
       // and serviceRegistry. 
       sessionFactory = configuration.buildSessionFactory(serviceRegistry); 

      } catch (Exception e) { 
       throw e; 
      } 
     } 
     return sessionFactory; 
    } 

    /** 
    * Close session factory. 
    */ 
    public static void closeSessionFactory() 
    { 
     if(sessionFactory!=null) 
     { 
      sessionFactory.close(); 
     } 
    } 
} 

答えて

0

これは非常に正常です。 初めてHibernateを構成し、セッションファクトリを使用するとき(つまりプログラムを実行するとき)は、あなたのPOJOファイル&のマップファイル、POJOとデータベースが一致していることを確認してください。 最初の実行には常に時間がかかります

+0

私は非常に短い時間を要する同じ休止状態の方法を使用している他のプログラムを見てきました。私のコードでできることは何ですか? –

+0

ローカルネットワークにデータベースがありますか?悪いネットワーク接続が原因で遅延スタートアップが発生する可能性があります。 –

+0

私のチームは当社のネットワークでMySQLワークベンチを使用しています –

関連する問題