-->
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.  [ 3 posts ] 
Author Message
 Post subject: Session.Find Problem
PostPosted: Mon Jun 20, 2005 11:54 am 
Hi,

Using the table Below, i'm triying to select the list of interfaces whose port number is 300310901.

Code:
+---------------+--------------+------+-----+---------+-------+
| Field         | Type         | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| Port          | int(9)       |      | PRI | 0       |       |
| IP            | varchar(15)  |      | PRI |         |       |
| Masque        | varchar(15)  | YES  |     | NULL    |       |
| PortsOuverts  | varchar(255) | YES  |     | NULL    |       |
| Subnet        | smallint(6)  |      | MUL | -1      |       |
| Nom           | varchar(50)  | YES  |     | NULL    |       |
| Domaine       | varchar(50)  | YES  |     | NULL    |       |
| DHCP          | tinyint(1)   | YES  |     | 1       |       |
| DNSPrimaire   | varchar(15)  | YES  |     | NULL    |       |
| DNSSecondaire | varchar(15)  | YES  |     | NULL    |       |
| Passerelle    | varchar(15)  | YES  |     | NULL    |       |
+---------------+--------------+------+-----+---------+-------+


This is the function that i m using :

Code:
      public ArrayList SelectionInt(int ident,string query)
      {
         try
         {
               
            Configuration cfg = new Configuration();
            cfg.AddXmlFile("D:\\Mappfile1\\Interface.hbm.xml");
            ISessionFactory factory = cfg.BuildSessionFactory();
            ISession session = factory.OpenSession(); 
            //IList list1 = session.Find("from Port where id<6");
            //IList list1 = session.Find(query+ident);
            IList list1 = session.Find("select * from Interface where port=300310901");
            //IList list1 = session.Find("from Interface where nom = 'print-srv'");
            //Query  q1 = session.CreateQuery("from Interface where nom = 'print-srv'");
            //ScrollableResults interf = q1.scroll();
            

            //session.Flush ();
            
            ArrayList list = new ArrayList();
            foreach(Interface interf in list1)
            {
               list.Add(interf);
            }
            session.Close();
            return list;
            
         }
         catch (System.Exception ex) { Console.WriteLine(ex.Message); }
         return null;
      }


The problem is that i don't get the right result (the same as when i execute query directly in the database) so when i execute the query on the database i got the following result :

Code:
+----------------+
| IP             |
+----------------+
| 192.168.10.160 |
| 192.168.12.160 |
| 192.168.14.160 |
| 192.168.2.160  |
| 192.168.3.160  |
| 192.168.4.160  |
| 192.168.5.160  |
| 192.168.6.160  |
| 192.168.7.160  |
+----------------+


but via Nhibernate i get :
Code:
192.168.10.160
192.168.10.160
192.168.10.160
192.168.10.160
192.168.10.160
192.168.10.160
192.168.10.160
192.168.10.160
192.168.10.160


Nine time the first line.

Please can some one help me. I m availble for any more detail.

Thank u in advance


Top
  
 
 Post subject: Mapping file
PostPosted: Tue Jun 21, 2005 3:13 am 
Here is the mapping file that i'm using :

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="IntMapLib.Interface, IntMapLib" table="Interface">

      <id name="Port" column="Port" type="Int32" length="9">
         <generator class="assigned" />
      </id>
            
      <property name="Subnet" type="Int16" length="6"/>
      <property name="Domaine" type="String" length="50"/>
      <property name="Dhcp" type="Int16" length="1"/>
      <property name="Ip"  not-null="true" type="string" length="15"/>
      <property name="Portsouverts" type="string" length="255"/>
      <property name="Nom" type="String" length="50"/>
      <property name="Dnsprimaire" type="String" length="15"/>
      <property name="Dnssecondaire" type="String" length="15"/>
      <property name="Passerelle" type="String" length="15"/>
      <property name="Masque" type="string" length="15"/>
   </class>
</hibernate-mapping>


Does it corresponds to the table Interface Below. I have a doubt about the declaration of Ip as it's a primary key... have i to define it differently in the mapping file??

Please any help.


Top
  
 
 Post subject:
PostPosted: Tue Jun 21, 2005 2:15 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Bonjour :wink:

Try this:
Code:
IList list1 = session.Find("select * from Interface I where I.Port=300310901");


As "Port" is the identifier, you can use session.Load(); and you shouldn't write "select *" :)

HTH

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


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