Home > .Net, NHibernate > How to do mapping of NCLOB into string in NHibernate

How to do mapping of NCLOB into string in NHibernate

I want to describe some error, which is accepted, while mapping NCLOB in NHibernate.

Working with Oracle database, we use “NVARCHAR2” type for strings. But this type has a constrain: it could contain no more then 2000 characters. If one needs to store some long text in Oracle, he will use an NCLOB type.

But, while mapping this type, next error is accepted:
ORA-01461: can bind a LONG value only for insert into a LONG column“.

How can we avoid this error? Two ways are possible:

1) Setting coulumn’s type to “AnsiString”:

        <property name="Contents" column="CONTENTS" type="AnsiString"/> 

2) Mapping by attribute:

        [Property(Column="CONTENTS", Type="AnsiString")]

And the error disappears… isn’t it great? 🙂

Categories: .Net, NHibernate Tags: , , , , ,
  1. Alexandre
    November 8th, 2011 at 00:11 | #1

    Thanks a lot!

  2. July 8th, 2012 at 02:19 | #2

    Excellent! Thanks.

  1. No trackbacks yet.