• hibernate4 使用及 新特性


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

    使用hibernate4所需要的jar包 在lib equired(必选的), 该文件夹中的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
  • 相关阅读:
    WebService cxf提供接口
    在文件系统的某一个目录中查找某一个字符串
    在notepad++中插件安装的办法
    windows中的oracle12SE后启动的系统服务的列表
    在windows环境初步了解tuxedo
    使用MS VS的命令来编译C++程序
    我所常用的git命令
    使用python对文件中的数值进行累加
    C++中继承关系中的同名隐藏和对策
    用eclipse来制作并使用可执行的jar文件
  • 原文地址:https://www.cnblogs.com/zhao123/p/4009661.html
Copyright © 2020-2023  润新知