Archive

Posts Tagged ‘NHibernate’

NHibernate working with Unsigned Value types like uint, sbyte, short etc.

April 30th, 2011 No comments

NHibernate working with Unsigned Value types like uint, sbyte, short etc.

We want to share one of the first experiences during developing with NHibernate. We immediately bumped in to serious problem with supporting unsigned Value types like

uint, ulong, sbyte

etc .  Natively those types are not fully supported by NHibernate.

You probably will ask “why we need those types?” Data that comes in some special formatting binary way form streaming where packet size is very important, so many optimizations are used. Our task was deserialize those compressed messages and at the end all data have to be stored in database tables. Additional that affected on our solution was demand to serialize data back to binary format from database tables.

The simplest and fast solutions were to duplicate properties int and uint but this was very ugly and not developer friendly proposal (from our point of view of cause). Additionally we have had plenty of such unsigned fields.

private uint m_value;

 

private int VlaueInt

{

get{ return (int)m_value;}

set { m_value = (uint)value; }

}

 

 

public uint ValueUint

{

get { return m_value; }

set { m_value = value; }

}

The second option were implementation of IUserType which means I have to create type that NHibernate can work with, but this solution wasn’t an option for us as well, because we didn’t wanted that our users that are going to use those Types will be aware of NHibernate existence. What will happen if we will choose to move all our data model to Entity framework for example.

Read more…

Categories: .Net, C#, NHibernate Tags:

How to do mapping of NCLOB into string in NHibernate

April 11th, 2011 2 comments

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"/> 

Read more…

Categories: .Net, NHibernate Tags: , , , , ,

NHibernate configuration, set database connection credentials

March 11th, 2011 No comments

NHibernate configuration, set database connection credentials

Our team started to use NHibernate ORM, it used in part of the components of our Application (Mostly stand alone services).
There are interesting issues bloomed up:
How to use the same DB credentials while you are using NHibernate and standard ADO approach to retrieve, save and update your data. We have plenty Legacy code that cannot move to use NHibernate configuration file. Our main application used standard sql connection string from App.Config file, of cause we doesn’t want to maintain two configuration files.

“hibernate.cfg.xml” file contains basic configuration settings, used by NHibernate; for more detail see … [web site] User Id=;Password=;Data Source=;Pooling=false

Read more…

Categories: .Net, NHibernate Tags: ,

How to remove Oracle client

March 7th, 2011 No comments

In case that regular uninstall wizard is failing from any reason you always may remove client manually – by following this steps.

1. Remove Installation directory c:\Oracle
2. Remove c:\Program Files\Oracle
3. Remove Registry key HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE

Reinstall Oracle client again, hopefully your problem with the client will be solved – it worked for me number of times.

Categories: General Tags: , ,