hibernate 注解

来源:互联网 发布:vr软件 编辑:程序博客网 时间:2024/05/22 05:19

  

在配置文件中直接使用如下

<mapping class="com.bjsxt.hibernate.Husband"/>
<mapping class="com.bjsxt.hibernate.Wife"/>

在java中要使用如下来过的sessionfactory

Configuration cfg = new AnnotationConfiguration().configure();
SessionFactory sf=cfg.buildSessionFactory();



<?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="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
        <property name="connection.username">jd</property>
        <property name="connection.password">jd</property>
        <property name="dialect">org.hibernate.dialect.OracleDialect</property>
       <!--
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@localhost:1521:SXT</property>
        <property name="connection.username">scott</property>
        <property name="connection.password">tiger</property>
      <property name="dialect">org.hibernate.dialect.OracleDialect</property>
       -->


        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>


        


        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>


        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>


        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>


        <!-- Drop and re-create the database schema on startup
        <property name="hbm2ddl.auto">update</property>
-->
        <!--   -->
        <mapping resource="com/bjsxt/hibernate/Student.hbm.xml"/>
        <mapping resource="com/bjsxt/hibernate/StuIdCard.hbm.xml"/>
<mapping class="com.bjsxt.hibernate.Husband"/>
<mapping class="com.bjsxt.hibernate.Wife"/>



    </session-factory>


</hibernate-configuration>


Configuration cfg = new AnnotationConfiguration().configure();
SessionFactory sf=cfg.buildSessionFactory();

0 0
原创粉丝点击