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.