【发布时间】:2013-06-11 16:01:28
【问题描述】:
我发现有两种方法可以初始化hibernate SessionFactory,
-
通过 org.hibernate.cfg.Configuration,读取 hibernate.cfg.xml 进行配置,我将获得 java 代码
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
-
通过 org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean bean,我将获得 java 代码
@Autowire
私有 SessionFactory 会话工厂
两者都让我得到预期的结果。但是在应用程序使用方面有什么不同吗?例如,Web 应用程序似乎更喜欢方法 2,因为我阅读的教程就是以这种方式配置的。
【问题讨论】: