0

Before stating the problem, please look at the code

Database(Oracle) SQL:

create table test_tab(
 id number,
 Name varchar2(50)
);

Corresponding Class in C#:

public class TestTable
    {
        private long id;
        public virtual long Id {
            get {
                return id;
            }
            set {
                id = value;
            }
        }

        private string name;
        public virtual string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }
    }

The mapping file for this:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DataTransfer" namespace="DataTransfer">
  <class name="DataTransfer.Models.TestTable, DataTransfer" table="TEST_TAB">
    <id name="Id" column="ID" type="long" unsaved-value="0">
      <generator class="sequence">
        <param name="sequence">
          seq_test
        </param>
      </generator>
    </id>
    <property name="Name" column="NAME" type="string" not-null="false"/> 
  </class>
</hibernate-mapping>

The "TestTable" class is inside the Models folder under DataTransfer project

hibernate configuration figuration file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
    <property name="connection.connection_string">Data Source=xe;Persist Security Info=True;User ID=hr;Password=hr;Unicode=True</property>
    <property name="show_sql">false</property>
    <property name="dialect">NHibernate.Dialect.Oracle9Dialect</property>
    <!-- mapping files -->
    <mapping assembly="DataTransfer" />
  </session-factory>
</hibernate-configuration>

And here is my DataAccessLayer Code;

public void AddToTestTable(Test_Tab user)
        {
            using (ISession session = GetSession())
            {
                using (ITransaction tx = session.BeginTransaction())
                {
                    try
                    {
                        session.Save(user);
                        session.Flush();
                    }
                    catch (NHibernate.HibernateException)
                    {
                        tx.Rollback();
                        throw;
                    }
                }
            }
        }

Now the problem is when I insert any value to the database(using simple ASP.NET form) nothing happens(even no exceptions!). But it worked perfectly when i did not use "Models" folder for TestTable Class and "Mappings" folder for mapping files. Please help me out.

3
  • How do you insert / add an entity to the DB ? Can you show some code please ? Do you flush the session for instance ? Or, how did you confiugre the flushmode ? Commented Jan 2, 2010 at 13:22
  • Oops!!!!!!!! I found my problem!! Commented Jan 2, 2010 at 13:52
  • 1
    Mr Flint, if you found the solution, you should create an "Answer" and accept it, so that future generations will benefit from it. Commented Jan 3, 2010 at 4:12

1 Answer 1

1

Make sure that the .hbm.xml mapping file is embedded as a resource in the assembly DataTransfer.

Sign up to request clarification or add additional context in comments.

1 Comment

When the mapping is not embedded as a resource, NH will throw an exception since it will treat the class as a 'non persitent' class. In other words: it will throw an exception since it does not know how to persist the entity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.