-->
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: Collections concrete class... posible disaster?
PostPosted: Fri Jun 30, 2006 12:10 am 
Contributor
Contributor

Joined: Tue May 30, 2006 1:25 am
Posts: 29
Hibernate version: 1.2.0.Alpha2

The test hbm
Code:
   <class name="NHb.DomainModel.Person, NHb.DomainModel" table="Persons" lazy="false">
      <id column="ID" name="_id" type="Int64" access="field">
         <generator class="sequence" >
            <param name="sequence">P_OID</param>
         </generator>
      </id>
      <property name="Name" column="PName" type="string" length="50" access="property"/>
      <bag name="Addresses" table="PERSON_ADDRESS" lazy="false">
         <key column="PERSONID"/>
         <many-to-many class="NHb.DomainModel.Address, NHb.DomainModel"/>
      </bag>
   </class>


the test class
Code:
  public class Person
  {
    public Person()
      : base()
    {
      _name = string.Empty;
    }
    private long _id;

    public long Id
    {
      get { return _id; }
      set { _id = value; }
    }
   
    private string _name;
    public string Name
    {
      get { return _name; }
      set { _name = value; }
    }

    private IList _addresses = new ArrayList();
    public IList Addresses
    {
      get { return _addresses; }
      set { _addresses = value; }
    }      
  }


When i load one instance of Person NHb create the collection Addresses with the concrete class NHibernate.Collection.PersistentBag so if i expose the collection Addresses (like the test) what kind of disaster can made a user of my class?

The user of my class can write something like this:
Code:
NHibernate.Collection.PersistentBag pb = personInstance.Addresses as NHibernate.Collection.PersistentBag;
if (pb != null)
{// this code will come executed
  pb.ForceInitialization();
  pb.Read();
  pb.ReadFrom(...)
  }


Wich is the best practies to work with collection?
We must use a wrapper every where?

Thanks.

_________________
Fabio Maulo.


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.