I'm new to NHibernate, so this might a common error ... but I can't find the solution.
When I create a new row in the db, the ID of my object is incremented by 1, but in the database, the ID is increment by 2, meaning that my object is not equal to the one saved in the database. The table has a PK with a sequence on it. If a create the row directly in the db, the sequence increment correctly by 1.
I use ActiveRecord on top of NHibernate and Oracle 10g.
My class is defined like this :
Code:
[ActiveRecord("ACTIV")]
public partial class Activity
{
[PrimaryKey(Column = "ID_ACTIV",UnsavedValue="0", SequenceName = "ID_ACTIV_SEQ")]
public int ID { get; set; }
The table is defined like this:
Code:
CREATE TABLE "PRIMHEURE"."ACTIV"
(
"ID_ACTIV" NUMBER(13,0) NOT NULL ENABLE,
...
CONSTRAINT "PK_ACTIV" PRIMARY KEY ("ID_ACTIV") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "USERS" ENABLE,
...
CREATE OR REPLACE TRIGGER "PRIMHEURE"."ACTIV_TRIGGER" BEFORE
INSERT ON "ACTIV" FOR EACH ROW BEGIN
SELECT "ID_ACTIV_SEQ".nextval INTO :NEW.ID_ACTIV FROM dual;
Thanks