Hibernate 2.0--5.0.11各版本创建SessionFactory

在学习过程中,发现版本更替,创建会话工厂方式也不同,在这里稍微总结下;
欢迎评论,多多交流。


Configuration conf = new Configuration().configure();
默认读取hibernate.cfg.xml配置文件,有变动请自行修改。


hibernate 2.x以及之前版本创建SessionFactory

  • SessionFactory sessionFactory = conf.buildSessionFactory();

hibernate 3.2+**创建SessionFactory

3.2开始引入Annotations & Entity Manager*

  1. SessionFactory sessionFactory = conf.buildSessionFactory();

  2. SessionFactory sf = new AnnotationConfiguration()
    .configure().buildSessionFactory();


hibernate 4.0+版本**创建SessionFactory

过时Annotation,取而代之为Configuration

你可能感兴趣的:(hibernate)