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。不須要考慮怎麼建表

相關文章
相關標籤/搜索