首页 > 系统服务 > 详细

hibernate4 使用及 新特性

时间:2014-10-07 19:38:44      阅读:363      评论:0      收藏:0      [点我收藏+]

hibernate4.x已经在官网出现一段时间了.
下载地址: http://hibernate.org/orm/downloads/

使用hibernate4所需要的jar包 在lib\required(必选的), 该文件夹中的jar必选都要copy,其他文件夹的可以有选择性的copy; 

1.buildSessionFactory

Configuration config = new Configuration();//
        SessionFactory factory = config.buildSessionFactory();

被下面退换,否则引入包会报错 org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect‘ not set

Configuration cfg = new Configuration().configure();
         @SuppressWarnings("deprecation")
         ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
         .applySettings(cfg.getProperties()).buildServiceRegistry();
         SessionFactory factory = cfg.buildSessionFactory(serviceRegistry);

2.annotation注解

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

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

3.自动建表

 Configuration cft = new Configuration().configure();
        SchemaExport export = new SchemaExport(cft);
        export.create(true, true);

4.数据库方言设置

<property name=”dialect”>org.hibernate.dialect.MySQL5Dialect</property>
在3.3版本中连接MySQL数据库只需要指明MySQLDialect即可。在4.1版本中可以指出MySQL5Dialect

 

hibernate4 使用及 新特性

原文:http://www.cnblogs.com/zhao123/p/4009661.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!