Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4027214
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:04:07+00:00 2026-05-20T11:04:07+00:00

I am starting to work with Nhibernate and Oracle for a project. The database

  • 0

I am starting to work with Nhibernate and Oracle for a project.
The database is Oracle 9.2 and I can’t change the schema or anything.
I am using NH3.0 and the Oracle.DataAccess.dll ver 2.111.7.20.

So far I’ve mapped a couple of table and have done some queries. Everything works pretty well.
I’ve bumped into a problem now and I don’t know how to fix it.
The company who’s designed the database thought it was a good idea to create all the alphanumeric fields as CHAR instead of VARCHAR or VARCHAR2.

I’ve mapped all these columns as String and my classes have String fields defined.
Later on I was trying to load an entity by its primary key, defined as CHAR(10) in Oracle.
The key I was trying to load is only 7 characters long
EG: ‘CI00252’
Apparently my entity can’t be loaded.
Profiling the query with NHProf I can see that my query is fine and if I try to execute it in Oracle Sql-Developer I get the resultset.
I can only manage to make it work if I pad my string like this ‘CI00252 ‘.

Considering that most of the fields defined on the database are CHAR, it is impossible for me to pad everything before executing the query.
What can I do to fix this problem?

PS: I’ve seen some other people with the same problem here but I couldn’t find any appropriate answer.

UPDATE:

I was reading a blog and this guy had a similar problem with another data-type.I’ve tried to adpapt the code

public SqlType[] SqlTypes
    {
        get
        {
                SqlType[] types = new SqlType[1];
                types[0] = new SqlType(DbType.StringFixedLength);
                return types;
                }
    }

**

and, apparently, everything is working but … I don’t know why.

using System;
using System.Data;
using NHibernate;
using NHibernate.SqlTypes;
using NHibernate.UserTypes;

namespace ConsoleOracleNhibernate.OracleTypes
{
    public class CharUserType : IUserType
    {
        public object NullSafeGet(IDataReader rs, string[] names, object owner)
        {
            string resultString = (string)NHibernateUtil.String.NullSafeGet(rs, names[0]);
            if (resultString != null)
                return resultString.Trim();
            return null;
        }

        public void NullSafeSet(IDbCommand cmd, object value, int index)
        {
            if (value == null)
            {
                NHibernateUtil.String.NullSafeSet(cmd, null, index);
                return;
            }

            value = ((String)value).Trim();

            NHibernateUtil.String.NullSafeSet(cmd, value, index);
        }

        public object DeepCopy(object value)
        {
            if (value == null) return null;
            return string.Copy((String)value);
        }

        public object Replace(object original, object target, object owner)
        {
            return original;
        }

        public object Assemble(object cached, object owner)
        {
            return DeepCopy(cached);
        }

        public object Disassemble(object value)
        {
            return DeepCopy(value);
        }

        public SqlType[] SqlTypes
        {
            get
            {
                SqlType[] types = new SqlType[1];
                types[0] = new SqlType(DbType.StringFixedLength);
                return types;
            }
        }

        public Type ReturnedType
        {
            get { return typeof(String); }
        }

        public bool IsMutable
        {
            get { return false; }
        }

        public new bool Equals(object x, object y)
        {
            if (x == null || y == null) return false;
            return x.Equals(y);
        }

        public int GetHashCode(object x)
        {
            return x.GetHashCode();
        }
    }
}

and my mapping:

<key-property name="CustomerCode" column="ANCOCO" type="ConsoleOracleNhibernate.OracleTypes.CharUserType, ConsoleOracleNhibernate" length="10"></key-property>

Is there anyone here who can try to help me to understand what’s happening?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:04:08+00:00Added an answer on May 20, 2026 at 11:04 am

    My answer is in the update of the question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am starting to work with the Three20 library and created a UIButton using
I am just starting my journey into learning databases/SQL and the like. I decided
I have just started to work as a freelance iPhone developer. Earlier I used
Why doesnt this work? I need it to start out at 1 instead of
I am just starting out with Lucene, and I feel like I must have
I'm just starting with the xcode business and so far so good, except for
Is there a way to make this work? (Scala 2.8.1) class A def f(implicit
class ABC is an abstract base class. class X is its subclass. There's some
Started to have an issue this afternoon with the delayed_job process, found that the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.