码迷,mamicode.com
首页 > 系统相关 > 详细

hibernate4 使用及 新特性

时间:2014-10-07 20:26:14      阅读:537      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   使用   ar   文件   数据   

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 使用及 新特性

标签:style   blog   http   color   io   使用   ar   文件   数据   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!