zoukankan      html  css  js  c++  java
  • hibernate配置

    hibernate可以由xml配置和properties文件配置,这里讲一下properties配置。

    与xml配置相识,将hibernate.properties放在主程序下,系统会自动调用。properties、中书写属于cfg.xml的内容

    demo:

    hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect
    hibernate.connection.driver_class=com.mysql.jdbc.Driver
    hibernate.connection.url=jdbc:mysql://localhost:3306/demo
    hibernate.connection.username=root
    hibernate.connection.password=123
    hibernate.show_sql=true

    这时候要取得数据库表的映射文件,需要这样:

    Configuration cfg=new Configuration().addClass("com.beans.User.class");

    这时才会加载User表的映射文件,然后可以取得sessionFactory:

    SessionFactory sessionFactory=cfg.buildSessionFactory();

    你也可以使用xml配置hibernate的配置文件

    在src目录下加入hibernate.cfg.xml,具体内容我就不多说了。

    当这样配置之后,获取SessionFactory:

    SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();

    其实,hibernate的配置文件命名为hibernate.cfg.xml只是一个默认,系统默认读取罢了。如果hibernate.cfg.xml命名为aaa.cfg.xml,怎么取读这个配置文件呢?

    SessionFactory sessionFactory=new Configuration().configure("aaa.cfg.xml").buildSessionFactory();

    注意:xml配置和properties配置可以同时使用,当这种情况的时候,xml配置中的配置会覆盖properties配置中的相同属性

  • 相关阅读:
    Gatling 条件判断
    Gatling脚本编写技巧篇(二)
    Gatling脚本编写技巧篇(一)
    性能测试-pidstat 问题定位分析
    REACT——无状态组件
    REACT——react-transition-group 实现动画
    REACT——生命周期函数
    REACT——ref的使用
    REACT——虚拟DOM
    REACT——Props、status与render
  • 原文地址:https://www.cnblogs.com/aigeileshei/p/5400598.html
Copyright © 2011-2022 走看看