views:

156

answers:

1

I am using NHibernate against a legacy database which uses Char column types (fixed Strings). I am mapping the char columns to strings in properties. Currently my criteria queries are failing if the value against which i am querying is not padded with spaces such that the length of the string is equal to the char column length. I dont want to manually pad in this way for all values. I was kind of looking that NHibernate will take care of this for me.

I tried the mapping with the following options:

<property name="Account">
  <column name="Account" sql-type="char(9)" length="9"/>
</property>

and

<property name="Account" type="AnsiChar">
  <column name="Account"/>
</property>

The first has no affect and the problem with the second mapping is that it assumes that the property type should be of type System.Char and not string. I am looking for a mapping where i can map Oracle's Char data type to normal string.

A: 

I had to create a UserType to trim the strings.

Jeremy Stein
For me it is not the padded strings returned from database which is a cause of concern, it is more that my criteria query parameter values have to be padded with appropriate length while doing a select on an object.
Dinesh Manne
If I recall correctly, that was part of my UserType implementation. I had to override equals to compare trimmed strings. You shouldn't have to pad a string before you send it to the DB in a WHERE clause -- it should automatically pad it for you.
Jeremy Stein