hibernate4相对hibernate3的一些变化

看视频学习hibernate,视频中讲解的是3.4版本的hibernate,我下载的是最新的hibernate4.1.7版本,在此将使用过程中发现发现的一些不同之处做个总结:

1. hibernate3.4版本,anotation包和hibernate核心包是分开的,而hibernate 4把anotation和核心包放在一起发布了。(应该是3.5就一起发布了)

2. dialect,3.4与4.1的dialect略有不同,3.4中mysql的配置是MySQLDialect,但4里面对mysql有3种配置分别为:

MySQL5 org.hibernate.dialect.MySQL5Dialect
MySQL5 with InnoDB org.hibernate.dialect.MySQL5InnoDBDialect
MySQL with MyISAM org.hibernate.dialect.MySQLMyISAMDialect

对数据库引擎进行了细分,具体使用有何细节差别,暂且不知。

3. 4.1版本中buildSessionFactory()已经被buildSessionFactory(ServiceRegistry ServiceRegistry)取代

解决办法:

Configuration cfg = new Configuration();
ServiceRegistry serviceRegistry =new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();

SessionFactory sf = cfg.configure().buildSessionFactory(serviceRegistry);

4. org.hibernate.cfg.AnnotationConfiguration;
Deprecated. All functionality has been moved to Configuration
这个注解读取配置的class已经废弃,现在读取配置不需要特别注明是注解,直接用Configuration cfg = new Configuration();就可以读取注解。

猜你喜欢

转载自jy03100000.iteye.com/blog/2203169