关于Hibernate与Oracle10g中的触发器问题
首先给出我的实体配置,这里为了方便就只给一个表了
步骤一:首先在Oracle10g中,创建了序列User_SEQ,语句如下
create sequence User_SEQ
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 20;
步骤二:然后创建一个针对表User的触发器User_trig
create or replace trigger User_trig
before insert on User
for each row
begin
select User_seq.nextval into:new.user_id from dual;
end User_trig;
步骤三:在Hibernate的实体映射xml中,写下如下代码
<?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"><hibernate-mapping> <class name="entity.user" table="user" select-before-update="true"> <id name="id" type="java.lang.Integer"> <column name="user_id" /> <generator class="sequence" > <param name="sequence">admin_seq</param> </generator> </id> <property name="name" type="java.lang.String"> <column name="admin_name" length="20" not-null="true" /> </property> <property name="pass" type="java.lang.String"> <column name="admin_pass" length="20" not-null="true" /> </property> </class></hibernate-mapping>