-->
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: ISet, ICollection, collection mapping
PostPosted: Mon Jan 07, 2008 2:20 am 
Newbie

Joined: Mon Dec 03, 2007 6:54 pm
Posts: 7
From the NHibernate docs:
NHibernate requires that persistent collection-valued fields be declared as an interface type

I don't really understand why. If your collection implements ICollection shouldn't this suffice?

Consider a class which holds a collection of items:

Code:
public class Customer
{

        private ICollection orders;

        public ICollection Orders
        {
            get { return orders; }
            set { orders = value; }
        }
}



This all works nicely with NHibernate - the only thing is that I want orders to be a concrete type (eg OrderList:CollectionBase) and not an ICollection

If I change it to OrderList I receive a cast exception.

What is the "correct" way to do this so Orders is exposed as an OrderList and not generic ICollection.

Yes I realise OrderList is NOT an interface type but I don't understand why NHibernate requires this.


Last edited by wal on Mon Jan 07, 2008 5:47 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 07, 2008 4:38 am 
Newbie

Joined: Sat Sep 22, 2007 5:42 am
Posts: 10
Hello!

ICollection is an interface, an array of orders isn't.
Use stryngly typed IList<Order>, Iesi.Collection.ISet etc. depending on your hibernate mapping.


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.