-->
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.  [ 2 posts ] 
Author Message
 Post subject: Persist my custom collection
PostPosted: Mon Feb 19, 2007 5:34 pm 
Newbie

Joined: Mon Feb 19, 2007 5:18 pm
Posts: 3
Location: Columbus, Ohio
NHibernate version: 1.2.0.1001

I have a class:"Automobile" which has a property:"Drivers" that I would like to return an instance of a DriverCollection class. DriverCollection inherits System.Collections.Collectionbase and implements IList. (I have done this because the documentation, and examples, seem to indicate that the property:"Drivers" should return an IList. (when using a bag)

I am able to persist Automobile if Drivers returns IList, but not DriverCollection. Why is this the case if DriverCollection implements IList?

Here's a mapping example:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="myPersistenceApp" namespace="myPersistenceApp">
<class name="Car" table="Automobiles">

<id name="SerialNum" column="SerialNum" type="int">
<generator class="assigned"/>
</id>

<bag name="Drivers" table="driverLookup" lazy="true">
<key column="serialNum"/>
<one-to-many class="Driver"/>
</bag>

<property column="color" type="String" name="Color" />
<property column="speed" type="int" name="Speed" />
<property column="weight" type="int" name="Weight" />

</class>
</hibernate-mapping>

_______________________________________


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 19, 2007 6:39 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
This has to do with NHibernate's use of proxies. You can only accurately use the interface. However you can use a generic collection, IList<Driver>, or you can have DriverCollection act as a wrapper around IList like this:

Code:
public DriverCollection Drivers{

  get{
    if(this._driverCollection == null){
      this._driverCollection = new DriverCollection(this._innerDriverList);
    }
    return this._driverCollection;
  }
}


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