string query = "from MAgency ma where ma.statusflag= :ma.statusflag";
 IList<MAgency> magency = session.CreateQuery(query).SetString("ma.statusflag", 
"1").List<MAgency>();

Should be 

 string query = "from MAgency ma where ma.statusflag= :statusflag";
 IList<MAgency> magency = session.CreateQuery(query).SetString("statusflag", 
"1").List<MAgency>();

now, be sure statusflag is indeed of type string.

  ----- Original Message ----- 
  From: Dick Negrana 
  To: [email protected] 
  Sent: Wednesday, November 04, 2009 5:38 PM
  Subject: [nhusers] Re: How to use parameters in Nhibernate 2.0.1


  Thanks for your response. I did what did you recommend in using parameter but 
there is still no result...
  Anyone can help me?



  On Wed, Nov 4, 2009 at 8:42 PM, Fabio Maulo <[email protected]> wrote:

    ma.statusflag= :ma.statusflag

    that is not a valid parameter name; use something like:    :pStatusFlag


    2009/11/4 silentdk <[email protected]>



      Guys,

      Anyone can help me...

      How to create create query with the use of HQL parameters in
      Nhibernate 2.0.1. I am newbie in using NHibernate...
      Please see my code below.


      --CLASS--
      namespace HOGPManPower.DomainModel
      {
         public class MAgency
         {
             private string m_oid;
             private string m_agencyname;
             private string m_description;
             private string m_statusflag;
             private DateTime m_lastupdate;
             private string m_updateby;

             public MAgency()
             {
             }
             public virtual string oid
             {
                 get { return m_oid; }
                 set { m_oid = value; }
             }
             public virtual string agencyname
             {
                 get { return m_agencyname; }
                 set { m_agencyname = value; }
             }
             public virtual string description
             {
                 get { return m_description; }
                 set { m_description = value; }
             }
             public virtual string statusflag
             {
                 get { return m_statusflag; }
                 set { m_statusflag = value; }
             }
             public virtual DateTime lastupdate
             {
                 get { return m_lastupdate; }
                 set { m_lastupdate = value; }
             }
             public virtual string updateby
             {
                 get { return m_updateby; }
                 set { m_updateby = value; }
             }

         }

      --TABLE MAPPING---
      ?xml version="1.0" encoding="utf-8" ?>
      <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
       <!--namespace="HOGPManPower.DomainModel"
       assembly="HOGPManPower.DomainModel"
       schema="HRDBA" >-->
       <class name="HOGPManPower.DomainModel.MAgency,
      HOGPManPower.DomainModel" table="MAgency" lazy="true">
         <id name="oid" column="OID" type="String" length="36">
           <!--<column name="OID" type="String" length="36">-->
           <generator class="uuid.hex" />
         </id>
         <property name="agencyname" type="String" length="50"></property>
         <property name="description"></property>
         <property name="statusflag"></property>
         <property name="lastupdate"></property>
         <property name="updateby"></property>
       </class>
      </hibernate-mapping>

      --hibernate.cfg.xml--
      <?xml version="1.0" encoding="utf-8" ?>
      <configuration>
       <configSections>
         <section name="hibernate-configuration"
         type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
         <!--<section name="log4net"
      type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />-->
       </configSections>

       <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
         <session-factory>
           <property
      name="connection.provider">NHibernate.Connection.DriverConnectionProvider,
      NHibernate</property>

           <!-- This is the Oracle.Client.dll provider for ORACLE Server --
      >
           <property
      name="connection.driver_class">NHibernate.Driver.OracleClientDriver</
      property>


           <!--HRDBAPPS Server-->
           <property name="connection.connection_string">
             Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)
      (HOST=172.17.3.77)(PORT=1521)))(CONNECT_DATA=(SERVER=SHARED)
      (SERVICE_NAME=HRDBAPPS)));User ID=HRDBA;Password=hrdba
           </property>

           <property name='prepare_sql'>true</property>
           <property name="show_sql">true</property>
           <property name="dialect">NHibernate.Dialect.OracleDialect</
      property>
           <mapping assembly="HOGPManPower.DomainModel"/>
         </session-factory>
       </hibernate-configuration>

      This is my query---

       public override void Load()
             {
                 ISession session = sessionFactory.OpenSession();
                 Object obj = "1";

                 try
                 {
                     string query = "from MAgency ma where
      ma.statusflag= :ma.statusflag";
                     IList<MAgency> magency = session.CreateQuery
      (query).SetString("ma.statusflag", "1")
                         .List<MAgency>();

                 }
                 catch (Exception ex)
                 {

                     throw new Exception(ex.Message, ex.InnerException);
                 }

                 finally
                 {
                     session.Close();
                 }

             }

             public override bool Insert(object obj)
             {
                 Boolean ret = false;
                 if (obj is MAgency)
                 {
                     MAgency objToSave = (MAgency)obj;


                     ISession session = sessions.OpenSession();
                     ITransaction transact = session.BeginTransaction();

                     try
                     {
                         objToSave.lastupdate = CFunctionUtils.getServerDate
      ();


                         session.Save(objToSave);
                         transact.Commit();
                         ret = true;

                     }
                     catch (Exception ex)
                     {
                         transact.Rollback();
                         throw new Exception(ex.Message,
      ex.InnerException);
                     }

                     finally
                     {
                         session.Close();
                     }

                 }
                 return ret;
             }

      There is no error in Nhibernate but there is no result count that
      get.  The Entity count is 0?







    -- 
    Fabio Maulo






  

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to