Stefan Steiger
Stefan Steiger

Reputation: 82156

Nhibernate: Exception occurred getter of

Question: I continue to get this nhibernate error when I try to insert an instance of clsSettings into the database:

Exception occurred getter of nhDBapi.DB.Tables.clsSettings.UID

See the class below, all of the methods below the class don't work, because of this exception.

The funny thing is, it works when everything is in an executable called nhDBapi.exe, and even when it's in the dll, the table schema gets created correctly.

When I move the exact same code into API_nHibernate.dll loaded by MailServer.exe, then it stops working...

The only difference between the two is in the exe, I use:

[NHibernate.Mapping.Attributes.Class(Name = "nhDBapi.DB.Tables.clsSettings, nhDBapi", Table = "T_lsSettings")]

while in the dll i use:

[NHibernate.Mapping.Attributes.Class(Name = "nhDBapi.DB.Tables.clsSettings, API_nHibernate", Table = "T_lsSettings")]

which should be correct.

Here the class:

using System;
using System.Collections.Generic;
using System.Text;

namespace nhDBapi.DB.Tables
{

    [NHibernate.Mapping.Attributes.Class(Name = "nhDBapi.DB.Tables.clsSettings, API_nHibernate", Table = "T_lsSettings")]
    public class clsSettings
    {

        [NHibernate.Mapping.Attributes.Id(Name = "UID", Column = "S_UID", TypeType = typeof(System.Guid))]
        public virtual System.Guid UID
        {
            get { return m_UID; }
            set { m_UID = value; }
        } // UserID

        protected System.Guid m_UID;


        [NHibernate.Mapping.Attributes.Property(Name = "Settings", Column = "S_Settings", TypeType = typeof(System.Byte[]))]
        public virtual System.Byte[] Settings
        {
            get { return m_Settings; }
            set { m_Settings = value; }
        } // UserID


        protected System.Byte[] m_Settings;



    } // End partial class lsSettings


} // End Namespace nhDBapi.DB.Tables

And here all the insert methods I tried:

// nhDBapi.DBaccess.Insert<nhDBapi.DB.Tables.clsDomains>(x);
public static void InsertRef<T>(ref T RowToAdd)
{
    /*
    List<T> lsRows = new List<T>();
    lsRows.Add(RowToAdd);

    Insert<T>(lsRows);
    lsRows.Clear();
    lsRows = null;
    */
    NHibernate.ISession session = m_bsfSessionFactory.OpenSession();
    NHibernate.ITransaction transaction = session.BeginTransaction();

    session.SaveOrUpdate(RowToAdd);


    transaction.Commit();
    session.Close();
    transaction.Dispose();
    session.Dispose();

} // End Sub Insert



// nhDBapi.DBaccess.Insert<nhDBapi.DB.Tables.clsDomains>(x);
public static void Insert<T>( T RowToAdd)
{
    /*
    List<T> lsRows = new List<T>();
    lsRows.Add(RowToAdd);

    Insert<T>(lsRows);
    lsRows.Clear();
    lsRows = null;
    */
    NHibernate.ISession session = m_bsfSessionFactory.OpenSession();
    NHibernate.ITransaction transaction = session.BeginTransaction();

    session.SaveOrUpdate(RowToAdd);


    transaction.Commit();
    session.Close();
    transaction.Dispose();
    session.Dispose();

} // End Sub Insert


// nhDBapi.DBaccess.Insert<nhDBapi.DB.Tables.clsDomains>(xx);
public static void Insert<T>(List<T> ListOfRowsToAdd)
{
    NHibernate.ISession session = m_bsfSessionFactory.OpenSession();
    NHibernate.ITransaction transaction = session.BeginTransaction();

    // Tell NHibernate that this object should be saved
    // commit all of the changes to the DB and close the ISession
    try
    {

        for (int i = 0; i < ListOfRowsToAdd.Count; ++i )
        {
            session.SaveOrUpdate(ListOfRowsToAdd[i]);
        }

        /*
        foreach (T tThisRow in ListOfRowsToAdd)
        {
            // session.Save(tThisRow);
            session.SaveOrUpdate(tThisRow);
        } // Next tThisRow
        */

        transaction.Commit();
        session.Close();
        transaction.Dispose();
        session.Dispose();
    } // End try
    catch (Exception ex)
    {
        MsgBox(ex.Message, "Error");
        //Console.WriteLine(ex.InnerException.Message);
        System.Environment.Exit(1);
    } // End catch

} // End Sub Insert

Upvotes: 0

Views: 968

Answers (1)

Mauricio Scheffer
Mauricio Scheffer

Reputation: 99720

IIRC the Name property of NHibernate.Mapping.Attributes.Class is not the type name but the NHibernate entity name. It shouldn't contain the assembly name. In fact, you don't even need to define the Name property, NHibernate will infer it for you. It's only there in case you want to override it.

So if this issue is really caused by this, remove the Name property and it should work. If not, there's some other difference.

Upvotes: 1

Related Questions