0

I tried to run the Nhibernate in my project but it throughing one error "No persister for: web.BackEndModel.TeamDetailsDb" below is my solution explore.

my project hierarchy

solution : NhibernateClient

project : web

folder : BackEndModel

  File : TeamDetailsDb.cs

folder : Controller

folder : model

folder : view

file : web.hbm.xml

and this is the piece of code i used for saving the data

NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
            cfg.SetProperty("dialect", "NHibernate.Dialect.MySQLDialect");
            cfg.SetProperty("connection.driver_class", "NHibernate.Driver.SqlClientDriver");
            cfg.SetProperty("connection.connection_string", "Data Source=.;Initial Catalog=OPLsite;Integrated Security=True");
            //cfg.SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu");
           // cfg.AddAssembly("");
            ISessionFactory sessionFactory = cfg.BuildSessionFactory();
            ISession session = sessionFactory.OpenSession();
            ITransaction transaction = session.BeginTransaction();



            TeamDetailsDb command = new TeamDetailsDb();
            command.OwnerName = collection["OwnerName"];
            command.TeamName = collection["TeamName"];
            session.Save(command);
            transaction.Commit();
            session.Close();

and this is my web.hbm.xml

    <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   namespace="web.BackEndModel.TeamDetailsDb"
                   assembly="web">

  <class name="TeamDetailsDb" table="TeamDetails">
    <id name="id" column="id" type="int">
      <generator class="identity"></generator>
    </id>
    <property name="OwnerName"  column="OwnerName" type="String"/>
    <property name="TeamName"   column="TeamName"  type="String"/>
    <mapping resource="web.hbm.xml" assembly="web" />
  </class>
</hibernate-mapping>

and this is my web config file..

     <configSections>
    <section  name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>

  <nhibernate>
    <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
    <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2000Dialect" />
    <add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
    <add key="hibernate.connection.connection_string" value="Data Source=myServer;Initial Catalog=myDatabase;Persist Security Info=True;" />
  </nhibernate>

my teamDetailsDb.cs

i am very new to this, please help me on this, pls becoz i am running out of time....

1 Answer 1

0

Yes thank you to all, I found out the reason why it was not working i changed

cfg.SetProperty("dialect", "NHibernate.Dialect.MySQLDialect");

to

cfg.SetProperty("dialect", "NHibernate.Dialect.MsSql2008Dialect");

also i changed the Web.hbm.xml to TeamDetailsDb.hbm.xml

now my TeamDetailsDb.hbm.xml is

    <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   namespace="web.BackEndModel"
                   assembly="web">

  <class name="TeamDetailsDb" table="TeamDetails">
    <id name="id" column="id" type="int">
      <generator class="identity"></generator>
    </id>
    <property name="OwnerName"  column="OwnerName" type="String"/>
    <property name="TeamName"   column="TeamName"  type="String"/>

  </class>
</hibernate-mapping>

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.