hibernate4.0+版本和3.0+版本的区别总结

hibernate4.0+版本和3.0+版本的区别总结

马老师说的好。要穿一手鞋,so,本身总结下hibernate4.1版本中的新特性和hibernate3.3作区别 数据库

1.数据库方言设置 app

<property name=”dialect”>org.hibernate.dialect.MySQL5Dialect</property> ui

在3.3版本中链接MySQL数据库只须要指明MySQLDialect便可。在4.1版本中能够指出MySQL5Dialect spa

2.buildSessionFactory hibernate

4.1版本中buildSessionFactory()已经被buildSessionFactory(ServiceRegistry ServiceRegistry)取代 开发

解决办法: get

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

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

3.annotation function

org.hibernate.cfg.AnnotationConfiguration;

Deprecated. All functionality has been moved to Configuration

这个注解读取配置的class已经废弃,如今读取配置不须要特别注明是注解,直接用Configuration cfg = new Configuration();就能够读取注解。

Hibernate4.1版本中推荐使用annotation配置,因此在引进jar包时把requested里面的包所有引进来就已经包含了annotation必须包了

4.Hibernate4.1已经能够自动建表,因此开发时只须要本身开发类而后配置好就OK。不须要考虑怎么建表

相关文章
相关标签/搜索