473,406 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 3436

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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.