0

I use Fluent NHibernate and I need to use GeneratedBy.Native() for Id generation to support Oracle,DB2 and MSSQL databases. If I try to run it like this on Oracle and insert new record to the table I get:

Could not execute query: select hibernate_sequence.nextval from dual
System.Data.OracleClient.OracleException (0x80131938): ORA-02289: sequence does not exist

Mapping class:

public sealed class ListDataMap : ClassMap<ListData>
{
    public ListDataMap()
    {
        Table("LIST_DEF");

        Id(x => x.Id, "ID").Not.Nullable().GeneratedBy.Native();
        //other mapping
    }
}

How can I specify the name of the sequence? I don't want to use hibernate_sequence because I will need more than 1 sequence and I don't want to have 1 shared sequence.

Thanks!

Ondřej Vykouk
  • 273
  • 1
  • 4
  • 9

1 Answers1

5

I have found the answer here: http://thatextramile.be/blog/2007/07/native-id-generation-with-nhibernate/

It is simple as this:

Id(x => x.Id, "ID").Not.Nullable().GeneratedBy.Native(
    builder => builder.AddParam("sequence", "SEQ_LIST_DEF")
);
Ondřej Vykouk
  • 273
  • 1
  • 4
  • 9