-->
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.  [ 1 post ] 
Author Message
 Post subject: NHIbernate and custom collections
PostPosted: Mon Oct 24, 2005 7:48 am 
Hi!

I'm using NHibernate in my project. I wanted to create collections for my classes because there are many calculated properties and I need to be able to sort collections by these properties.

So, I created my own base collection that has reference to IList that I get from NHibernate. This base class implements all needed interfaces for databinding. Then I wrote custom object comparer to easily sort my collections using reflection. All common collection functionality is implemented in base class. Each collection has just constructor that calls base class constructor and indexer property that returns object with correct type.

When my manager class needs to return some of my collection it makes query, creates collection with correct type and gives IList to this collection's constructor. Now constructor tries to cast it to ArrayList. It succeeds when I get IList by using IQuery or ICriteria. It doesn't succeed if I want to return some object's property as my collection (mapped as bag etc). In this case my base class creates new ArrayList and copies all objects from IList to ArrayList as IList interface is still implemented.

I want to ask if there is any better way to manage custom collections? What can be side effects of my solution? My goal is to have library that applications can use without knowing a thing about NHibernate and database.

With best regards,
Gunnar Peipman


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.