title: Hibernate initialize SessionFactory
body: <p>I found there are two ways to initialize hibernate SessionFactory,</p>
  
  <ol>
  <li><p>via org.hibernate.cfg.Configuration, hibernate.cfg.xml is read for configuration and I will have java code </p>
  
  <blockquote>
    <p>SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();  </p>
  </blockquote></li>
  <li><p>via org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean bean and I will have java code  </p>
  
  <blockquote>
    <p>@Autowire<br>
       private SessionFactory sessionFactory</p>
  </blockquote></li>
  </ol>
  
  <p>Both get me the results as expected. But is there any difference in terms of application usage? For example, web application seems to prefer method 2 as the tutorials I read were configured in that way. </p>