-->
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.  [ 1 post ] 
Author Message
 Post subject: Obtain many-to-many collection
PostPosted: Mon Mar 26, 2007 10:36 am 
Regular
Regular

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

I have a problem. I have developed a persistentClass that contains a collection (many-to-many relattion). The problem is that when I add an Item into collection it is saved correctly, but when I get this persistent class in other session, the collection is empty, and I don't know why this collection doesn't contain the items.

Can you help me please? Thanks in advance!


Code:
      public Model.Client getClient(string codi)
      {
         Model.Client client = null;
         try
         {
            NHibernate.ITransaction transaction = this.session.BeginTransaction();
            client = (Model.Client)this.session.Get(typeof(Model.Client), codi);
            transaction.Commit();
         }
         catch (Exception ex)
         {
            Console.WriteLine(ex.Message);
            Console.WriteLine(ex.InnerException.Message);
         }
         return client;
      }

------------------------------------

      public void addDireccioEntrega(string codi_client, Model.DireccioEntrega entrega)
      {
         try
         {
            this.save(entrega);
            Model.Client client = (Model.Client)this.session.Get(typeof(Model.Client), codi_client);
            if (client != null) client.Direccions_entrega.Add(entrega);
            this.session.Flush();
         }
         catch (Exception ex)
         {
            Console.WriteLine(ex.Message);
            Console.WriteLine(ex.InnerException.Message);
         }
      }


Code:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="Model.Client, Broker" table="CLIENT">
      <id name="Codi" column="CODI" type="String">
         <generator class="assigned" />
      </id>
      <property name="Descripcio" column="DESCRIPCIO" type="String"/>
                 ......
      <set name="Direccions_entrega" table="CLIENTS_TENEN_DIRECCIO_ENTREGUES" cascade="all">
         <key column="CODI"/>
         <many-to-many column="ADREƇA" class="Model.DireccioEntrega, Broker"/>
      </set>
   </class>
</hibernate-mapping>



Code:
namespace Model
{
   public class Client
   {

      private string codi;
      private string descripcio;
      private string alies;
      private System.DateTime data_alta;
      private string nif;
      private Model.Direccio direccio;
      private Iesi.Collections.ISet direccions_entrega;
      private Iesi.Collections.ISet contactes;

      protected Client ()
      {
         this.codi = "";
         this.descripcio = "";
         this.alies = "";
         this.data_alta = System.DateTime.MinValue;
         this.nif = "";
         this.direccio = null;
         this.direccions_entrega = new Iesi.Collections.ListSet();
         this.contactes = new Iesi.Collections.ListSet();
      }

      public Client(string codi)
      {
         this.codi = codi;
         this.descripcio = "";
         this.alies = "";
         this.data_alta = System.DateTime.MinValue;
         this.nif = "";
         this.direccio = null;
         this.direccions_entrega = new Iesi.Collections.ListSet();
         this.contactes = new Iesi.Collections.ListSet();
      }

      public Client(string codi, string descripcio, string alies, System.DateTime data_alta, string nif, Model.Direccio direccio)
      {
         this.codi = codi;
         this.descripcio = descripcio;
         this.alies = alies;
         this.data_alta = data_alta;
         this.nif = nif;
         this.Direccio = direccio;
         this.direccions_entrega = new Iesi.Collections.ListSet();
         this.contactes = new Iesi.Collections.ListSet();
      }

      #region Propietats

      public virtual string Descripcio
      {
         get { return this.descripcio; }
         set { this.descripcio = value; }
      }

      public virtual string Alies
      {
         get { return this.alies; }
         set { this.alies = value; }
      }

      public virtual string Codi
      {
         get { return this.codi; }
         set { this.codi = value; }
      }

      public virtual System.DateTime Data_alta
      {
         get { return this.data_alta; }
         set { this.data_alta = value; }
      }

      public virtual string Nif
      {
         get { return this.nif; }
         set { this.nif = value; }
      }

      public virtual Model.Direccio Direccio
      {
         get { return this.direccio; }
         set { this.direccio = value; }
      }

      public virtual Iesi.Collections.ISet Direccions_entrega
      {
         get { return this.direccions_entrega; }
         set { this.direccions_entrega = value; }
      }

      public virtual Iesi.Collections.ISet Contactes
      {
         get { return this.contactes; }
         set { this.contactes = value; }
      }

      #endregion
   }
}


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

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.