l 数据库方言设置
<propertyname=”dialect”>org.hibernate.dialect.MySQL5Dialect</property>
在3.3版本中连接MySQL数据库只需要指明MySQLDialect即可。在4.1版本中可以指出MySQL5Dialect
l buildSessionFactory
4.1版本中buildSessionFactory()已经被buildSessionFactory(ServiceRegistry ServiceRegistry)取代
解决办法:
Configuration cfg = new Configuration();
ServiceRegistry serviceRegistry =new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
SessionFactory sf =cfg.configure().buildSessionFactory(serviceRegistry);
l 缓存
缓存设置改为<propkey="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
综上所述:
Hibernate4对于hibernate3.x变动只要是session管理的变动,就是Sessionfactory的创建变了。其他都差不多。