Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
this is my postgres table
CREATE SEQUENCE student_id_seq;
CREATE TABLE student
(
  id integer NOT NULL  default nextval('student_id_seq'),
  first_name character varying,
  CONSTRAINT student_pkey PRIMARY KEY (id )
)
WITH (
  OIDS=FALSE
);
 
ALTER TABLE student
  OWNER TO postgres;
ALTER SEQUENCE student_id_seq owned by student.id;
 
I have write class for nhibernate like below...
[Class(Table = "student")]
public class Student
{
 private long _id;
 private string _studentname;
[Id(Name = "Id", Column = "id", UnsavedValue="0" )]
        [Generator(1, Class = "sequence")]
        [Param(Name = "student_id_seq")]
        public virtual long Id
        {
            get { return _id; }
            set { _id = value; }
        }
 
        [Property]
        [Column(1, Name = "studentname")]
        public virtual string studentname
        {
            get { return _studentname; }
            set { _studentname=value; }
        }
//other methods...
}
 
It throws error while call...
session.SaveOrUpdate(obj);
Error: could not get next sequence value
 
thanks
Posted 10-Apr-13 21:47pm
Edited 11-Apr-13 22:11pm
v2
Comments
Bernhard Hiller at 11-Apr-13 2:58am
   
Doesn't postgres have a datatype for the autoincrementing integer - I thought it was "serial".
Aarti Meswania at 11-Apr-13 3:06am
   
I have change sequence to serial
[Generator(1, Class = "serial")]
but still not working

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I have solve this
hope it will useful to them who facing same problem...
[Class(Table = "student")]
public class Student
{
 private long _id;
 private string _studentname;
[Id(Name = "Id", Column = "id", UnsavedValue="0" )]
        [Generator(1, Class = "sequence")]
        [Param(2,Name = "sequence", Content = "student_id_seq")] // Line I have changed
        public virtual long Id
        {
            get { return _id; }
            set { _id = value; }
        }
 
        [Property]
        [Column(1, Name = "studentname")]
        public virtual string studentname
        {
            get { return _studentname; }
            set { _studentname=value; }
        }
//other methods...
}
NOTE : postgres is case sensitive if you have write name of object in double quote then you have to write name in .net in exact manner. so, when create sequence do not write sequence name (e.g. student_id_seq) in double quotes
 
Happy Coding!
Smile | :)
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 295
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 12 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100