hibernate中主键生成策略为sequence的写法

在hibernate中,如果在实体关系影射中,主键生成策略为序列(对应数据库为oracle)则详细的配置如下(ormpping文件)

 

 

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="entity.Student" table="test_qjk_stu">
       
       
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="sequence">
            <!-- 指定序列的名字test_qjk_stu_seq-->
            <param name="sequence">test_qjk_stu_seq</param>
            </generator>
        </id>

       
       
       
        <property name="stuName" type="java.lang.String">
            <column name="stuname" length="20" />
        </property>
    </class>
</hibernate-mapping>

 

对应的hibernate.cfg.xml文件写法如下:

 

 

<?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">

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

    <session-factory>
        <property name="connection.url">
            jdbc:oracle:thin:@192.168.100.235:1521:mpptest
        </property>
        <property name="connection.username">gmcc</property>
        <property name="connection.password">skywin</property>
        <property name="connection.driver_class">
            oracle.jdbc.OracleDriver
        </property>
        <property name="dialect">org.hibernate.dialect.OracleDialect</property>
        <mapping resource="entity/Student.hbm.xml" />

    </session-factory>

</hibernate-configuration>

你可能感兴趣的:(oracle,Hibernate,xml,jdbc,MyEclipse)