-->
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: Collections
PostPosted: Wed Jun 29, 2005 11:43 pm 
i am new to NHibernate so forgive me if this is a stupid question. But when designing my domain model, can i use strongly typed collections that inherit from an ArrayList? I would think i could as it still implments IList.


Top
  
 
 Post subject:
PostPosted: Thu Jun 30, 2005 2:37 am 
I am fairly new to NHibernate too, but for what its worth; here's my take on the matter:

The issue is that any code internal or external to your class will need to interface with the collection using the IList interface. This is because NHibernate assigns its own persistent collection implementation to your IList member variable when an instance of your class is created by an NHibernate session.

If any of your code casts the interface back to your assumed implementation (like ArrayList), then you will get a cast exception.

So, in answer to your question, you can use a strongly typed collection if you like, as long as all communication with the collection is performed via the IList interface. This of course negates the point of having a strongly typed collection in the first place.

One alternative you might explore is to create a strongly typed collection wrapper around a private IList member collection. Set the access strategy in the NHibernate mapping file to "field". Have another field in your class referencing the strongly typed instance (which just wraps your private IList). Then return your strongly typed collection in your getter.

I haven't tried this before, but it might work.


Top
  
 
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.