Fluent NHibernate - how to specify sequence name for Id with GeneratedBy.Native()

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!

c#
fluent-nhibernate
nhibernate-mapping
fluent-nhibernate-mapping
asked on Stack Overflow Nov 22, 2012 by Ondřej Vykouk

1 Answer

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")
);
answered on Stack Overflow Nov 22, 2012 by Ondřej Vykouk

User contributions licensed under CC BY-SA 3.0