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

  • Home
  • SEARCH
  • 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 6150435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:36:42+00:00 2026-05-23T19:36:42+00:00

I am reading data from an external organisation using Oracle.DataAccess through the Oracle10g provider.

  • 0

I am reading data from an external organisation using Oracle.DataAccess through the Oracle10g provider. One of the tables has a composite id made up of these fields.

course:
  institutioncode: "X11"
  coursecode:      "N100"
  campuscode:      "A"
  entryyear:       2011
  entrymonth:      10

The problem is that the campus code is allowed to be null by the external provider instead of empty. This leads to nHibernate returning collections that contain null references instead of course entities.

Other domain objects will use these fields to refer to this course entity as well, so this is actually used as a key and I can’t easily remap to use a surrogate key.

From the source in tag 3.1.0GA, the check that is causing this behavior can be found in Nhibernate.Type.ComponentType.Hydrate(IDataReader rs, string[] names, ISessionImplementor session, object owner). This is always refusing the possibility that a key-property could be null. Could this change to make nullability an option on key-property and key-reference properties?

Failing that, how would you recommend reading this data directly with nHibernate?

  • 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-23T19:36:42+00:00Added an answer on May 23, 2026 at 7:36 pm

    ok my first comment didnt worked out on References (ManyToOne). So here my alternative solution: a usertype to work around the check.

    class CourseMap : ClassMap<Course>
    {
        public CourseMap()
        {
            CompositeId()
                .KeyProperty(c => c.InstitutionCode)
                .KeyProperty(c => c.CourseCode)
                .KeyProperty(c => c.CampusCode, key => key.Type(typeof(MyUserType)))
                .KeyProperty(c => c.EntryYear)
                .KeyProperty(c => c.EntryMonth);
        }
    }
    
    class MyUserType : IUserType
    {
        public object Assemble(object cached, object owner)
        {
            return DeepCopy(cached);
        }
    
        public object DeepCopy(object value)
        {
            return value;
        }
    
        public object Disassemble(object value)
        {
            return DeepCopy(value);
        }
    
        public new bool Equals(object x, object y)
        {
            return object.Equals(x, y);
        }
    
        public int GetHashCode(object x)
        {
            return (x == null) ? 0 : x.GetHashCode();
        }
    
        public bool IsMutable
        {
            get { return false; }
        }
    
        public object NullSafeGet(IDataReader rs, string[] names, object owner)
        {
            var value = NHibernateUtil.String.NullSafeGet(rs, names[0]);
            return (value == null) ? string.Empty : value;
        }
    
        public void NullSafeSet(IDbCommand cmd, object value, int index)
        {
            string d = string.IsNullOrEmpty((string)value) ? null : (string)value;
            NHibernateUtil.String.NullSafeSet(cmd, d, index);
        }
    
        public object Replace(object original, object target, object owner)
        {
            return DeepCopy(original);
        }
    
        public Type ReturnedType
        {
            get { return typeof(string); }
        }
    
        public SqlType[] SqlTypes
        {
            get { return new[] { SqlTypeFactory.GetString(100) }; }
        }
    }
    
    
    
    class SomeEntityMap : ClassMap<SomeEntity>
    {
        public EntityMap()
        {
            Id(e => e.Id).GeneratedBy.Assigned();
    
            References(e => e.Course)
                .Columns("InstitutionCode", "CourseCode", "CampusCode", "EntryYear", "EntryMonth")
                .Fetch.Join();  // important because we can't rely on values, NULL is invalid value
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading data from multiple serial ports. At present I am using a
I'm reading data from a serial port using an event listener from the SerialPort
I am reading data from a file that has, unfortunately, two types of character
After reading data from XML source I like to be able to show one
When reading data from the Input file I noticed that the ¥ symbom was
I'm reading data from a table( from a MySQL Database) with Hibernate SQL Query.
I'm reading data from a device which measures distance. My sample rate is high
I'm reading data from a stream into a char array of a given length,
I'm having some trouble reading data from a file into a vector of Orders.
How can i Load Temptable on Server B by reading data from Server A

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.