Oracle – How to properly use Fluent NHibernate to get the next Sequence in Oracle

fluent-nhibernatenhibernateoracle

I'm using NHibernate / Fluent NHibernate with Oracle and I'm running into an issue. I've got the following mapping file defined:

public OrderMap()
{
    Table("ORDERS");
    Id(x => x.OrderId, "ORDER_ID").GeneratedBy.Sequence("select ORDERS_SQ.nextval from orders");
    Map(x => x.CreatedBy, "CREATED_BY");
    Map(x => x.OrderStatusCd, "ORDER_STATUS_CD");
    Map(x => x.StoreGroupId, "STORE_GROUP_ID");
    Map(x => x.IsActive, "IS_ACTIVE");
    Map(x => x.OrderDate, "ORDER_DATE");
}

When I go to run my project I get the following error:

An invalid or incomplete configuration was used while creating a SessionFactory.

If I remove the .GeneratedBy.Sequence("select ORDERS_SQ.nextval from orders"); line, the application runs but I don't get the next sequence obviously when I save a record. I've tried doing just .GeneratedBy.Sequence("ORDERS_SQ"); but I just don't seem to get anything to work right.

Can anyone tell me the proper way to use Fluent NHibernate to get the next available sequence correctly please?

I'm using Fluent NHibernate 1.1 with NHibernate 3.0 Beta.

Thanks.

Best Answer

Just specify the name of the sequence:

Id(x => x.OrderId).Column("ORDER_ID").GeneratedBy.Sequence("ORDERS_SQ");

// Real working code:
Id(x => x.Id).GeneratedBy.Sequence("SEQ_Catalog1");
Related Topic