These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Nhibernate errors
PostPosted: Mon Oct 02, 2006 12:15 pm 
Regular
Regular

Joined: Mon Oct 02, 2006 12:03 pm
Posts: 62
I'm doing a simple sample project with C#. Only, I want create a simple User and add it to my database. I've created a form with textboxes that represents data user. And when I click on update button -->

when I perform it, VisualStudio says me that
Quote:
" Could not find a setter for property '_login' in class 'PersistentClasses.User'"


Code:
         PersistentClasses.UserFactory factory = new PersistentClasses.UserFactory();
            factory.saveUser(new PersistentClasses.User(this.LogintextEdit.Text,this.PasswordtextEdit.Text,this.NomtextEdit.Text,1));


Can you help me?

I've implemented my User class as:

Code:
using System;
using NHibernate.Cfg;

namespace PersistentClasses
{
   /// <summary>
   /// Descripción breve de Class1.
   /// </summary>
   //[Gentle.Framework.TableName("Users")]
   public class User
   {
      //[Gentle.Framework.TableColumn("LOGIN",true)]
      private string _login;
      //[Gentle.Framework.TableColumn("PASSWORD",true)]
      private string _password;
      //[Gentle.Framework.TableColumn("NOM",true)]
      private string _nom;
      //[Gentle.Framework.TableColumn("ROL",true)]
      private int _rol;

      public string Login
      {
         get { return this._login; }
         set { this._login = value; }
      }

      public int Rol
      {
         get { return this._rol; }
         set { this._rol = value; }
      }

      public string Nom
      {
         get { return this._nom; }
         set { this._nom = value; }
      }

      public string Password
      {
         get { return this._password; }
         set { this._password = value; }
      }

      public User()
      {
         this._login = "";
         this._password = "";
         this._nom = "";
         this._rol = -1;
      }

      public User(string login, string password, string nom, int rol)
      {
         this._login = login;
         this._password = password;
         this._nom = nom;
         this._rol = rol;
      }
   }
}


and User.hbm.cml is:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="PersistentClasses.User, PersistentClasses" table="USUARIS">
      <id name="_login" column="LOGIN" type="string" length="25">
         <generator class="increment" />
      </id>
      <property name="_password" column="PASSWORD" type="string" length="10"/>
        <property name="_nom" column="NOMR" type="integer" length="50"/>
        <property name="_rol" column="ROL" type="integer"/>
   </class>
</hibernate-mapping>


And my UserFactory Class:

Code:
using System;
using NHibernate;
using NHibernate.Cfg;

namespace PersistentClasses
{
   /// <summary>
   /// Descripción breve de UserFactory.
   /// </summary>
   public class UserFactory
   {

      Configuration config;
      ISessionFactory factory;
      ISession session;

      public UserFactory()
      {
         config = new Configuration();
         System.Collections.IDictionary props = new System.Collections.Hashtable();

         props["hibernate.connection.provider"] = "NHibernate.Connection.DriverConnectionProvider";
         props["hibernate.dialect" ] = "NHibernate.Dialect.MsSql2000Dialect";
         props["hibernate.connection.driver_class" ] = "NHibernate.Driver.SqlClientDriver" ;
         props["hibernate.connection.connection_string"] = "Server=SERVER2003;initial catalog=KoetDB;UserID=CABRE2;Password=CABRE2" ;
      
         foreach( System.Collections.DictionaryEntry de in props )
         {
            config.SetProperty( de.Key.ToString(), de.Value.ToString() );
         }

         config.AddAssembly("PersistentClasses");
         factory = config.BuildSessionFactory();
         session = factory.OpenSession();
      }

      /// <summary>
      /// Make sure we clean up session etc.
      /// </summary>
      public void Dispose()
      {
         session.Dispose();
         factory.Close();
      }

      public void saveUser (PersistentClasses.User user)
      {
         //NHibernate.Cfg.Configuration configuration = new Configuration();
         //configuration.AddClass(typeof(User));

         //NHibernate.ITransaction transaction = this.session.BeginTransaction();

         this.session.Save(user);

         //transaction.Commit();
         //session.Close();
      }
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 02, 2006 2:54 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
The default mapping in NHibernate is to properties. You are using the private member variable in your mapping. You can either:

1) Change them to use the public property names.
2) Set access="field" on your id/property mappings - this way NHibernate will use your private member variables directly via reflection


Top
 Profile  
 
 Post subject: cannot open connection
PostPosted: Tue Oct 03, 2006 3:40 am 
Regular
Regular

Joined: Mon Oct 02, 2006 12:03 pm
Posts: 62
Thanks, it's solved.

Other question, when I execute :

Code:
      public void saveUser (PersistentClasses.User user)
      {
         NHibernate.ITransaction transaction = this.session.BeginTransaction();

         this.session.Save(user);

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


it throws an exception how that:

Quote:
NHibernate.ADOException' en nhibernate.dll

Información adicional: cannot open connection


the userFactory Class:

Code:
public class UserFactory
   {

      Configuration config;
      ISessionFactory factory;
      ISession session;

      public UserFactory()
      {
         config = new Configuration();
         System.Collections.IDictionary props = new System.Collections.Hashtable();

         props["hibernate.connection.provider"] = "NHibernate.Connection.DriverConnectionProvider";
         props["hibernate.dialect" ] = "NHibernate.Dialect.MsSql2000Dialect";
         props["hibernate.connection.driver_class" ] = "NHibernate.Driver.SqlClientDriver" ;
         props["hibernate.connection.connection_string"] = "Server=SERVER2003;initial catalog=KoetDB;UserID=CABRE2;Password=CABRE2" ;
      
         foreach( System.Collections.DictionaryEntry de in props )
         {
            config.SetProperty( de.Key.ToString(), de.Value.ToString() );
         }

         config.AddAssembly("PersistentClasses");
         factory = config.BuildSessionFactory();
         session = factory.OpenSession();
      }

      /// <summary>
      /// Make sure we clean up session etc.
      /// </summary>
      public void Dispose()
      {
         session.Dispose();
         factory.Close();
      }

      public void saveUser (PersistentClasses.User user)
      {
         NHibernate.ITransaction transaction = this.session.BeginTransaction();

         this.session.Save(user);

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


Top
 Profile  
 
 Post subject: cannot open connection
PostPosted: Tue Oct 03, 2006 3:41 am 
Regular
Regular

Joined: Mon Oct 02, 2006 12:03 pm
Posts: 62
Thanks, it's solved.

Other question, when I execute :

Code:
      public void saveUser (PersistentClasses.User user)
      {
         NHibernate.ITransaction transaction = this.session.BeginTransaction();

         this.session.Save(user);

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


it throws an exception how that:

Quote:
NHibernate.ADOException' en nhibernate.dll

Información adicional: cannot open connection


How dies NHibernate show it me?

the userFactory Class:

Code:
public class UserFactory
   {

      Configuration config;
      ISessionFactory factory;
      ISession session;

      public UserFactory()
      {
         config = new Configuration();
         System.Collections.IDictionary props = new System.Collections.Hashtable();

         props["hibernate.connection.provider"] = "NHibernate.Connection.DriverConnectionProvider";
         props["hibernate.dialect" ] = "NHibernate.Dialect.MsSql2000Dialect";
         props["hibernate.connection.driver_class" ] = "NHibernate.Driver.SqlClientDriver" ;
         props["hibernate.connection.connection_string"] = "Server=SERVER2003;initial catalog=KoetDB;UserID=CABRE2;Password=CABRE2" ;
      
         foreach( System.Collections.DictionaryEntry de in props )
         {
            config.SetProperty( de.Key.ToString(), de.Value.ToString() );
         }

         config.AddAssembly("PersistentClasses");
         factory = config.BuildSessionFactory();
         session = factory.OpenSession();
      }

      /// <summary>
      /// Make sure we clean up session etc.
      /// </summary>
      public void Dispose()
      {
         session.Dispose();
         factory.Close();
      }

      public void saveUser (PersistentClasses.User user)
      {
         NHibernate.ITransaction transaction = this.session.BeginTransaction();

         this.session.Save(user);

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 03, 2006 9:11 am 
Regular
Regular

Joined: Mon Oct 02, 2006 12:03 pm
Posts: 62
Note:

The connectionString that I use when use traditional Databases access is:

Code:
this.ConnectionStringSQLServer = "data source=SERVER2003;database=KoetDB;user id=CABRE2;password=CABRE2"


So, I supose that it's right, when I configure NHibernate -->

Code:
props["hibernate.connection.connection_string"] = "Server=SERVER2003;initial catalog=KoetDB;UserID=CABRE2;Password=CABRE2" ;


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.