您的位置:首页 > 其它

hibernate4.1版本中的新特性和hibernate3.3部分区别

2015-05-27 16:55 435 查看

1.数据库方言设置

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


在3.3版本中连接MySQL数据库只需要指明MySQLDialect即可。在4.1版本中可以指出MySQL5Dialect


2.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);
//或SessionFactory sf = cfg.buildSessionFactory(serviceRegistry);(试过可行)


3.annotation

org.hibernate.cfg.AnnotationConfiguration;

Deprecated. All functionality has been moved to Configuration

这个注解读取配置的class已经废弃,现在读取配置不需要特别注明是注解,直接用 Configuration cfg = new Configuration();就可以读取注解。

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

4.事务,hibernateTemplete

hibernate4已经完全可以实现事务了 与spring3.1中的hibernatedao,

hibernateTemplete等有冲突,所以spring3.1里已经不提供

hibernatedaosupport,hibernateTemplete
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  hibernate