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.  [ 4 posts ] 
Author Message
 Post subject: Newbie mapping to own generic list
PostPosted: Tue Dec 12, 2006 4:27 am 
Newbie

Joined: Tue Dec 12, 2006 3:47 am
Posts: 2
I made a class with a nested generic collection of items. This collection is a Domain.Objects.DomainObjectsList<Orders>.
This Collection is used in my Class Invoice.

Code:
public class Invoice
{
        // Properties   
        public virtual IList<Order> Orders
        {
           get
               {
                     return FTestOrders;
              }
        }      

        private Domain.Objects.DomainObjectsList<Order> FTestOrders = new Domain.Objects.DomainObjectsList<Order>();       
}


My mapping code looks like this:

Code:
<class name="Invoice" table="INVOICES" >
    <id name="FKey" column="INV_KEY" type="Int32" length="4" unsaved-value="0" access="field">
      <generator class="native"></generator>
    </id>   
    <bag name="Orders" cascade="all" access="field" >
      <key column="ORDER_KEY" />
      <one-to-many class="Order"/>
    </bag>
    </class>


After one Invoice with some Orders are loaded from the database, the generic list of orders are type of
Code:
NHibernate.Collection.Generic.PersistentGenericBag`1[Domain.Objects.Order]
and NOT type of
Code:
Domain.Objects.DomainObjectsList[Domain.Objects.Order]
.

How can i map the bag or a list to my own generic list?
Maybe i have to integrate a component?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 5:37 am 
Regular
Regular

Joined: Tue Aug 08, 2006 4:28 am
Posts: 96
Location: Hong Kong
Hi MarOh,

This can be done by implementing your own IPropertyAccessor and ISetter classes.

Change
Code:
<bag name="Orders" cascade="all" access="field" >
to
Code:
<bag name="Orders" cascade="all" access="type_of_your_IPropertyAccessor_class" >


I am no expert in NHibernate. I learnt this technique from Ayende's NHibernate Generics project: http://www.ayende.com/projects/nhiberna ... erics.aspx.

In fact the internal of NHibernate does not hard code the use of PersistentGenericBag class, but the default ISetter class make use of PersistentGenericBag.

Canton


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 8:55 am 
Newbie

Joined: Tue Dec 12, 2006 3:47 am
Posts: 2
Hi canton,

thanks for your answer. I red this article yesterday, very interesting. But i think there must be a more simple way to get the same solution with NHibernate Beta 1.2.

I think my collection must described as a kind of component. In this article is such a kind of implemantation posted: http://forum.hibernate.org/viewtopic.php?t=965167&highlight=generic

Is there a another way to tell NHibernate to create a generic list using by own list?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 12, 2006 9:57 pm 
Regular
Regular

Joined: Tue Aug 08, 2006 4:28 am
Posts: 96
Location: Hong Kong
MarOh,

I haven't tried component. To my understanding, component is a group of related values (e.g. FirstName and LastName could be combined to a component class Name). Component is not a collection.

This is legal
ISet<YourComponentClass>
But this is not
YourComponentCollectionClass<DomainObjectClass>

Translated to database point of view, a component consists of several values from a single row (e.g. FirstName and LastName in Table Customer).

Please correct me if I got it wrong.

Canton


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