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.  [ 3 posts ] 
Author Message
 Post subject: Help with my domain model and custom collections
PostPosted: Fri Oct 10, 2008 10:31 pm 
Newbie

Joined: Fri Oct 10, 2008 9:44 pm
Posts: 2
Before all, sorry my bad english. I will try do my best.

My application have this domain model:

1) A "BaseSuperClass" that implements a ILIST (not generic) and various custom properties and methods. This class is my custom collection for all collections inside my app.

2) Some of my business objects have collections of others business objects, and these collections are derived from my "BaseSuperClass". For example, I have a Customer Object that have a collection of Telephones. The implementation of the code is like this:

=== Customer ===

Public Class Customer
Private _Telephones As Telephones
...
Public Property Telephones() As Telephones
Get
Return Me._Telephones
End Get
Set ( Value As Telephones )
Me._Telephones = Value
End Set
End Property
End Class

=== Telephones ===

Public Class Telephones
Inherits BaseSuperClass
...
End Class

=== BaseSuperClass ===

Public Class BaseSuperClass
Implements System.Collections.IList
Implements System.IDisposable
Private _Coll As System.Collections.ArrayList
...
IList Code (Add, Contains, etc...)-> The IList methods use the "_Coll" arraylist
...
Some custom properties and methods
End Class

I have made some exhaustive tests, but all failed. The main problem occurs when NHibernate try to set the value of property "Telephones" on Customer Class. It try to set to a 'IPersistentCollection' and a invalid cast exception is thow:

"Invalid cast exception: cannot cast type 'IPersistentCollection' to 'Telephones'"

I have tried the tree maps below ([Assembly] is the name of my real assembly):

=== 1 ===

<bag name="Telephones" table="`Customers.Telephones`" cascade="all" inverse="true" collection-type="[Assembly].Telephones, [Assembly]">
<key column="`CustomerID`"/>
<one-to-many class="[Assembly].Telephone, [Assembly]"/>
</bag>

=== 2 ===

<component name="Telephones" class="[Assembly].Telephones, [Assembly]">
<bag name="Telephones" cascade="all-delete-orphan" lazy="false">
<key column="`CustomerId`" />
<one-to-many class="[Assembly].Telephone, [Assembly]"/>
</bag>
</component>

=== 3 ===

<set name="Telephones" lazy="false" inverse="true" cascade="none">
<key><column name="`CustomerId`"/></key>
<one-to-many class="[Assembly].Telephone, [Assembly]"/>
</set>

I confess that I have searched a lot in the last days and found nothing about this. Well, my question now is: The NHibernate can work with this model? My I need to redone it to fit on NH requirements?

Any help could be appreciated,
Best regards

Rogério


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 11, 2008 1:05 pm 
Newbie

Joined: Thu Apr 26, 2007 4:07 am
Posts: 7
Location: Ukraine
There are nice articles about NHibernate and custom collections:
http://devlicio.us/blogs/billy_mccafferty/archive/2007/12/03/custom-collections-with-nhibernate-part-i-the-basics.aspx

_________________
Stanislaw Tristan


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 11, 2008 5:48 pm 
Newbie

Joined: Fri Oct 10, 2008 9:44 pm
Posts: 2
s_tristan wrote:


Thank´s. I have read all that this guy writed about custom collections and NH (like IUserCollectionType), but does not apply to may case.

For example, I have implemented the IUserCollectionType on my "BaseSuperClass". No go. In a separate wrapper. No go too.

But I thank you for your interest on help me.


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