-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Oracle Sequece
PostPosted: Thu Aug 12, 2010 8:34 am 
Newbie

Joined: Thu Aug 12, 2010 8:22 am
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: Oracle Sequece
PostPosted: Thu Aug 12, 2010 8:57 am 
Newbie

Joined: Thu Aug 12, 2010 8:22 am
Posts: 2
I found the problem. I had a trigger on the Id colum and I also told NHibernate to manage the sequence. So the sequence was queried twice. Once by NHibernate and once with the trigger on the Id column. I dropped the trigger on the column and let NHibernate manage the sequece and it worked fine.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.