I have this kind of mapping....
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.test.hibernate.AttachFile" table="AttachFile">
<id name="fileId" column="fileId">
<generator class="sequence">
<param name="sequence">SEQ_AttachFile</param>
</generator>
</id>
<property name="fileName" column="fileName"/>
<property name="filePath" column="filepath"/>
</class>
</hibernate-mapping>
and i have a trigger in my ORACLE database like:
Code:
create trigger attachFile_trigger
before insert on AttachFile
for each row
begin
select SEQ_AttachFile.nextval into :new.fileId from dual;
end;
as you know, the ID will be generated from a sequence.
however, also in my database (ORACLE), i also define a TRIGGER that will get the next value of the sequence.
this is the reason why everytime i use may application and do insert a row on this table, the SEQUENCE will be incremented twice!. That is:
1. hibernate get the next value from SEQUENCE.
2. upon inserting the row, the trigger kicks off and take the next value from the SEQUENCE.
my question is, what generator class should I use to make the SEQUENCE gets incremented only once?.
or how will I redefine my mapping on this case?
Thanks in advance.