-->
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.  [ 2 posts ] 
Author Message
 Post subject: NHibernate.PropertyAccessException - HELP ME PLEASE
PostPosted: Sun Oct 16, 2005 3:49 pm 
Newbie

Joined: Sun Oct 16, 2005 3:37 pm
Posts: 2
Hi there.

I need help....


I have the follow code:


The class.
Code:
using System;

namespace RDestribBUS
{

    public class UF
    {


        private int m_Id;
      private string m_UF;
        private string m_Descricao;
      
        public virtual  int Id
        {
            get
            {
                return m_Id;
            }
        }

      public virtual  string uf
      {
         get
         {
            return m_UF;
         }
         set
         {
            m_UF=value;
         }
      }

        public virtual  string Descricao
        {
            get
            {
                return m_Descricao;
            }
            set
            {
                m_Descricao = value;
            }
        }




    }
}


The UF.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" >
  <class name="RDestribBUS.UF, RDestribBUS" table="UF">
    <id name="Id" type="Int32" column="UFId">
      <generator class="native" />
    </id>
    <property name="uf" column="UF" type="String(2)" />
    <property name="Descricao" column="Descricao" type="String(40)" />
  </class>
</hibernate-mapping>



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

namespace RDestribBUS
{

   public class MUF
   {
      ISessionFactory factory;
      Configuration config;
      ISession session;

      public MUF()
      {

         factory=config.BuildSessionFactory();

         session=factory.OpenSession();

         //SQL SERVER
         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=localhost;initial catalog=RDestrib;User ID=root;Password=123redhot" ;


         foreach( DictionaryEntry de in props )
         {
            config.SetProperty( de.Key.ToString(), de.Value.ToString() );
         }

         config.AddAssembly("RDestribBUS");

         factory = config.BuildSessionFactory();

         session = factory.OpenSession();



      }

      public IList getUFs()
      {

         
         ITransaction tx=session.BeginTransaction();

         IList uf;

         uf=session.CreateCriteria(typeof(UF)).List();
         
         return uf;


      }
      

   }
}



When I call getUFs() the follow error is displayed:

An unhandled exception of type 'NHibernate.PropertyAccessException' occurred in nhibernate.dll

Additional information: ArgumentException while setting the property value by reflection

Can you help me? I dont knwo what to do... :(


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 16, 2005 4:32 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
This is probably caused by you not defining a setter for the id property. You can either define one, or use one of the nosetter access strategies.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.