Hibernate为Oracle自动创建表且主键自增

1.注意:实体类映射表字段时不要使用oralce关键字,否则不能映射成功。
2.步骤:
    (1)往oralce里建一个sequence:
        
                  create sequence seq_id_supervision
                      minvalue 1
                      start with 1
                      increment by 1
         

         注:如果多个表要映射自增长主键,每个表要建一个sequence。
    (2)model映射配置:
        
          <id name="id">
	        <generator class="sequence">
		       <param name="sequence">
			     seq_id_letter
			</param>
		</generator>
	 </id>
         

    (3)Hibernate映射文件配置:
        
         <hibernate-configuration>
<session-factory>
	<property name="hibernate.connection.driver_class">
		oracle.jdbc.driver.OracleDriver
	</property>
	<property name="hibernate.connection.url">
		jdbc:oracle:thin:@localhost:1521:jf
	</property>
	<property name="hibernate.connection.username">jf</property>
	<property name="hibernate.connection.password">jf</property>
	<property name="hibernate.dialect">
             org.hibernate.dialect.OracleDialect
        </property>
	<property name="hibernate.show_sql">true</property>
	<property name="hibernate.hbm2ddl.auto">update</property>
	<property name="hibernate.cache.provider_class">
		org.hibernate.cache.HashtableCacheProvider
	</property>
	<mapping resource="com/chinasoft/jfb/model/LetterInformation.hbm.xml" />
</session-factory>
</hibernate-configuration>
         

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