title: How to use static block to initialize spring hibernate query function
body: <p>I am new to Spring Hibernate, so I am having this problem that cause by a function that initialize in a static block.</p>
  
  <p>This is my DAO class:</p>
  
  <pre><code>private static HibernateTemplate hibernateTemplate;
  public void setSessionFactory(SessionFactory sessionFactory) {
      hibernateTemplate = new HibernateTemplate(sessionFactory);
  }
  
  static{
      loadAllProvince();
  }
  public static void loadAllProvince ()  {
      List regionList = hibernateTemplate.find("FROM regions");
  
      if (regionList.size() &gt; 0 ) {           
         for (int i=0; i&lt;regionList.size(); i++) {                
            Object[] obj = (Object[]) regionList.get(i) ;
            mapRegion.put(obj[1].toString(), obj[0].toString());                  
         }                        
      }   
   }
  </code></pre>
  
  <p>This is the bean configuration in my applicationContext.xml:</p>
  
  <pre><code>&lt;bean id="regionDAOBean" class="com.dao.RegionDAO"&gt;
     &lt;property name="sessionFactory" ref="sessionFactoryBean"/&gt; 
  &lt;/bean&gt;
  </code></pre>
  
  <p>When I run my application, the exception say:</p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'regionDAOBean' defined in class path resource [applicationContext.xml]: 
  Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError
  </code></pre>
  
  <p>It was working find until I initialize the function in the static block, so what should I do in order to initialize the function in static block?</p>