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配置中的相同属性

  • 相关阅读:
    ASP.NET应用程序与页面生命周期
    Git源码管控规范
    redis cluster
    jwt token and shiro
    openapi and light-4j
    ps 证件照制作
    js eval 动态内容生成
    pdnovel 看书 读书 听书
    crawler 使用jQuery风格实现
    websocket聊天体验(二)
  • 原文地址:https://www.cnblogs.com/aigeileshei/p/5400598.html
Copyright © 2011-2022 走看看