Hi all,
I am using Oracle 9i with a table named EVENT that has a primary key column ID and a string column NAME. I created a sequence (SEQ_EVENT_ID) and a trigger to generate Ids automatically in this column whenever an item is inserted to simulate the "identity" feature supported by other databases.
I am using the following:
Hibernate version: 3.1.3
Database: Oracle9i
Definition of my primary key in mapping doc:
<hibernate-mapping package="devdb">
<class name="Event" table="EVENT">
<id name="Id" type="integer" column="ID" >
<generator class="sequence">
<param name="sequence">SEQ_EVENT_ID</param>
</generator>
</id>
<property name="Name" column="NAME" type="string" not-null="false" length="50" />
</class>
</hibernate-mapping>
The problem is that whenever I insert a new EVENT, hibernate queries the sequence (as expected, I must admit) and then my DB trigger queries the sequence as well which increments my Ids by two at every insertion.
Code used:
Code:
Client oNewEvent = new Client();
oNewEvent.setName("new test name...");
oSession.save(oNewEvent);
oSession.getTransaction().commit();
Logs by hibernate:
Hibernate: select SEQ_CLIENT_ID.nextval from dual
Hibernate: insert into CLIENT (NAME, ID) values (?, ?)
Basically, I need to be able to define my ID column in the mapping file, but I don't want hibernate to use it when I insert a new event. I want to enter the name of the event, to commit it and to let the database trigger take care of the ID column.
I have tried the <generator class="identity"/> tag, but since I am using Oracle, hibernate won't let me because Oracle does not really support idendity columns.
So how should I configure the <id...> tag in the mapping file so that Hibernate ignores it on insertion?
Thanks,
Huck