472,955 Members | 2,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,955 software developers and data experts.

NHibernate + Custom List: Unable to cast...

Hi,

I'm using NHibernate 1.2 (CR1), and I'm using a custom list (inherited from
BindingList(Of T) ) for all my lists.

The NHibernate documentation told me that I had to implement
IUserCollectionType to my custom list, which I did. But I still get an error
when trying to read the object: "
{"Unable to cast object of type
'NHibernate.Collection.Generic.PersistentGenericBa g`1[Ghost.clsPersonne]' to
type 'BaseFramework.BaseList`1[Ghost.clsPersonne]'."}"

I looked at the sample here
(http://analog-man.blogspot.com/2007/...ibernate.html),
but it didn't help a lot...

Does anybody knows what I'm doing wrong?

Thanks a lot in advance,

Pieter


This is my Custom List:
-----------------------

Public Class BaseList(Of T As BaseClass)
Inherits BindingList(Of T)
Implements IComponent, IUserCollectionType

...

#Region "IUserCollectionType Implementation"

Public Function ReplaceElements(ByVal original As Object, ByVal target
As Object, ByVal persister As ICollectionPersister, ByVal owner As Object,
ByVal copyCache As System.Collections.IDictionary, ByVal session As
ISessionImplementor) As Object Implements
IUserCollectionType.ReplaceElements
Dim Result As BaseList(Of T) = CType(target, BaseList(Of T))
Result.Clear()
For Each item As Object In CType(original, IEnumerable)
Result.Add(CType(item, T))
Next
Return Result
End Function

Public Overloads Function IndexOf(ByVal collection As Object, ByVal
entity As Object) As Object Implements IUserCollectionType.IndexOf
Return CType(collection, BaseList(Of T)).IndexOf(CType(entity, T))
End Function

Public Function Instantiate() As Object Implements
IUserCollectionType.Instantiate
Return New BaseList(Of T)()
End Function

Public Function Instantiate(ByVal session As ISessionImplementor, ByVal
persister As ICollectionPersister) As IPersistentCollection Implements
IUserCollectionType.Instantiate
Return New PersistentIdentifierBag(Of T)(session)
End Function

Public Function Wrap(ByVal session As ISessionImplementor, ByVal
collection As Object) As IPersistentCollection Implements
IUserCollectionType.Wrap
Return New PersistentIdentifierBag(Of T)(session, CType(collection,
BaseList(Of T)))
End Function

Public Overloads Function Contains(ByVal collection As Object, ByVal
entity As Object) As Boolean Implements IUserCollectionType.Contains
Return CType(collection, BaseList(Of T)).Contains(CType(entity, T))
End Function

Public Function GetElements(ByVal collection As Object) As IEnumerable
Implements IUserCollectionType.GetElements
Return CType(collection, IEnumerable)
End Function

#End Region

End Class

These are my mapping files:
----------------------------
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Ghost.clsEntreprise, Ghost" table="tblEntreprises"
dynamic-update="true" lazy="false">
<id name="EntrepriseID" column="EntrepriseID" type="Int32">
<generator class="identity" />
</id>
<property name="Nom" column="Nom" type="String" length="50" />
<bag name="Personnes" cascade="save-update" lazy="false">
<key column="EntrepriseID"/>
<one-to-many class="Ghost.clsPersonne, Ghost"/>
</bag>
</class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Ghost.clsPersonne, Ghost" table="tblPersonnes"
dynamic-update="true" lazy="false">
<id name="PersonneID" column="PersonneID" type="Int32" unsaved-value="0">
<generator class="identity" />
</id>
<property name="EntrepriseID" column="EntrepriseID" type="Int32"
length="4" />
<property name="Nom" column="Nom" type="String" length="50" />
<property name="Prenom" column="Prenom" type="String" length="50" />
<many-to-one name="Adresse" class="Ghost.clsAdresse, Ghost"
column="AdresseID" cascade="save-update" lazy="false"/>
</class>
</hibernate-mapping>
Mar 30 '07 #1
0 3402

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded...
0
by: a | last post by:
Q. Unable to get a Profile custom (object) collection to bind to GridView,etc (IList objects)? This is my first custom object so I may be doing something rather simple, wrong, or it may be...
0
by: a | last post by:
I need to create an instance of a custom object 'School.Teacher' and use it in a Profile object. I'm developing a bad case of "Pretzel Logic" thinking about this. Filling the custom object ...
0
by: Aquila Deus | last post by:
The documents on their website are completely wrong. Following is the a real example that works with NHibernate 1.0.2.0: <?xml version="1.0" encoding="utf-8"?> <configuration...
1
by: erin.sebastian | last post by:
Hello All, I am new to hibernate and new to nHibernate. I created a small app and when i try and run it i get the error i posted at the bottom of this message. I am using the helper class that...
0
by: beantaxi | last post by:
Hello all, I'm trying to write a simple program, using VS C# 2005 Express and SQL Server Express with NHib 1.0.2. No matter what I try, I'm unable to connect: cannot open connection at...
0
by: Pieter | last post by:
Hi, I'm using NHibernate 1.2 (CR1), and I'm using a custom list (inherited from BindingList(Of T) ) for all my lists. The NHibernate documentation told me that I had to implement...
2
by: Smithers | last post by:
I have a Windows Forms application that implements a plug-in architecture whereby required assemblies are identified and loaded dynamically. Here are the relevant classes: A = application =...
8
by: bryan.kardisco | last post by:
I'm currently trying to extend the TreeViewItem class so I can attach some additional attributes to the item. I created a custom class class myTreeNode : System.Windows.Controls.TreeViewItem...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
1
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.