hibernate hbm.xml文件

配置数据库连接1>
<hibernate-configuration>
    <session-factory>
        <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=yes)(FAILOVER=on)(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.1.6.1)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)))(LOAD_BALANCE=yes)(CONNECT_DATA=(SERVICE_NAME=RACDB)(FAILOVER_MODE=(TYPE=select)(DELAY=5)(METHOD=basic))))</property>
        <!--<property name="connection.url">jdbc:oracle:thin:@127.0.0.1:1521:MASTER</property>-->
        <property name="connection.username">usera</property>
        <property name="connection.password">pwda</property>
        <property name="connection.pool_size">5</property>
        <property name="show_sql">true</property>

<mapping resource="com/entity/QueryLog.hbm.xml"/>
<mapping resource="com/entity/Operator.hbm.xml"/>
    </session-factory>
</hibernate-configuration>

配置数据库连接2>
  <session-factory>
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@192.168.0.3:1521:ORA92</property>
        <property name="dialect">net.sf.hibernate.dialect.OracleDialect</property>
        <property name="connection.username">nnnnnnnn</property>
        <property name="connection.password">xxxxxxx</property>
        <property name="statement_cache.size">10</property>
        <property name="show_sql">false</property>
        <property name="connection.pool_size">5</property>
        <property name="hibernate.cglib.use_reflection_optimizer">false</property>
        <property name="use_outer_join">true</property>

        <mapping resource="com/Dictionary.hbm.xml"/>

    </session-factory>
配置数据库连接3>
<session-factory>
        <property name="connection.datasource">java:comp/env/jdbc/datasourcename</property>或
<property name="connection.datasource">XX_DataSource</property>(apusic下)或
<property name="connection.datasource">java:comp/env/XX_DataSource</property>(tomcate下)
<property name="show_sql">false</property>
<property name="connection.pool_size">5</property>
<property name="hibernate.cglib.use_reflection_optimizer">false</property>
<property name="use_outer_join">true</property>

<mapping resource="com/Dictionary.hbm.xml"/>

</session-factory>



实体间的关联关系
Order与Customer是m:1的关系
Order.hbm.xml
Order和一个Customer类型的成员变量
<many-to-one
    name="customer"
    column="customer_id"
    class="Customer"
    not-null="true"
/>
Customer.hbm.xml
Customer有一个orders集合,元素是Order
<set
    name="orders"
    cascade="delete"
    inverse="true"  被维护端
    >
    <key column="customer_id" />
    <one-to-many class="Order" />
</set>

你可能感兴趣的:(Hibernate)