【问题标题】:Where does session factory's method define database to be used?会话工厂的方法在哪里定义要使用的数据库?
【发布时间】:2018-01-14 11:55:44
【问题描述】:

我正在创建会话工厂对象,如下所示:

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

哪个类提到了我在 *.hbm.xml 文件中提到的数据库?

【问题讨论】:

    标签: database hibernate sessionfactory


    【解决方案1】:

    要使用的数据库在 hibernate.cfg.xml 文件中定义。在此文件中,您可以定义数据库连接统计信息以及映射要使用的类(如果您选择的话)。此处的连接统计信息示例:

    hibernate.cfg.xml form this tutorial:

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
    <session-factory>
      <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
      <property name="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521:MKYONG</property>
      <property name="hibernate.connection.username">mkyong</property>
      <property name="hibernate.connection.password">password</property>
      <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
      <property name="hibernate.default_schema">MKYONG</property>
    </session-factory>
    </hibernate-configuration>
    

    另请注意:Configuration - Hibernate Documentation

    (旁注:mkyong 的东西有时可能已经过时,但那个该死的家伙几乎单枪匹马地负责我目前的工作。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-22
      • 1970-01-01
      • 2020-02-20
      • 1970-01-01
      相关资源
      最近更新 更多