473,836 Members | 1,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

NHibernate + Custom List: Unable to cast...


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
IUserCollection Type 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.Col lection.Generic .PersistentGene ricBag`1[Ghost.clsPerson ne]' to
type 'BaseFramework. BaseList`1[Ghost.clsPerson ne]'."}"

I looked at the sample here
but it didn't help a lot...

Does anybody knows what I'm doing wrong?

Thanks a lot in advance,


This is my Custom List:

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


#Region "IUserCollectio nType Implementation"

Public Function ReplaceElements (ByVal original As Object, ByVal target
As Object, ByVal persister As ICollectionPers ister, ByVal owner As Object,
ByVal copyCache As System.Collecti ons.IDictionary , ByVal session As
ISessionImpleme ntor) As Object Implements
IUserCollection Type.ReplaceEle ments
Dim Result As BaseList(Of T) = CType(target, BaseList(Of T))
For Each item As Object In CType(original, IEnumerable)
Result.Add(CTyp e(item, T))
Return Result
End Function

Public Overloads Function IndexOf(ByVal collection As Object, ByVal
entity As Object) As Object Implements IUserCollection Type.IndexOf
Return CType(collectio n, BaseList(Of T)).IndexOf(CTy pe(entity, T))
End Function

Public Function Instantiate() As Object Implements
IUserCollection Type.Instantiat e
Return New BaseList(Of T)()
End Function

Public Function Instantiate(ByV al session As ISessionImpleme ntor, ByVal
persister As ICollectionPers ister) As IPersistentColl ection Implements
IUserCollection Type.Instantiat e
Return New PersistentIdent ifierBag(Of T)(session)
End Function

Public Function Wrap(ByVal session As ISessionImpleme ntor, ByVal
collection As Object) As IPersistentColl ection Implements
IUserCollection Type.Wrap
Return New PersistentIdent ifierBag(Of T)(session, CType(collectio n,
BaseList(Of T)))
End Function

Public Overloads Function Contains(ByVal collection As Object, ByVal
entity As Object) As Boolean Implements IUserCollection Type.Contains
Return CType(collectio n, BaseList(Of T)).Contains(CT ype(entity, T))
End Function

Public Function GetElements(ByV al collection As Object) As IEnumerable
Implements IUserCollection Type.GetElement s
Return CType(collectio n, IEnumerable)
End Function

#End Region

End Class

These are my mapping files:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhib ernate-mapping-2.2">
<class name="Ghost.cls Entreprise, Ghost" table="tblEntre prises"
dynamic-update="true" lazy="false">
<id name="Entrepris eID" column="Entrepr iseID" type="Int32">
<generator class="identity " />
<property name="Nom" column="Nom" type="String" length="50" />
<bag name="Personnes " cascade="save-update" lazy="false">
<key column="Entrepr iseID"/>
<one-to-many class="Ghost.cl sPersonne, Ghost"/>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhib ernate-mapping-2.2">
<class name="Ghost.cls Personne, Ghost" table="tblPerso nnes"
dynamic-update="true" lazy="false">
<id name="PersonneI D" column="Personn eID" type="Int32" unsaved-value="0">
<generator class="identity " />
<property name="Entrepris eID" column="Entrepr iseID" 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.cl sAdresse, Ghost"
column="Adresse ID" cascade="save-update" lazy="false"/>
Mar 30 '07 #1
0 3467

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

Similar topics

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 the custom employee class and have built it as a separate library (employee.dll). This employee.dll is being referenced by both the web service and the windows application. I face the following problem when I send this class to the webservice.
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 something else to do with the Profile object. Either way, I need help Here's a brief description of the code----------------------------------------------------------------------------------
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 'School.Teacher' as an ArrayList creates the proper information (see aspx code below), but I'm unable to use this ArrayList in the Profile object. The aspx code below shows the attempt and error message.
by: Aquila Deus | last post by:
The documents on their website are completely wrong. Following is the a real example that works with NHibernate <?xml version="1.0" encoding="utf-8"?> <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <configSections> <!-- SecurityException is thrown if NHibernate assembly is not in GAC. --> <section name="hibernate-configuration"
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 can be found here http://blogs.intesoft.net/simon/articles/16.aspx#36 . Does anyone know why this error might occur.. i have NO IDEA.... if you require anymore information please let me know and i will send it through. Thanks in advance! Erin
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 NHibernate.Impl.SessionFactoryImpl.OpenConnection() at NHibernate.Impl.SessionImpl.get_Connection() at NHibernate.Transaction.AdoTransaction.Begin(IsolationLevel
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 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.PersistentGenericBag`1' to
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 = Windows Forms class B = a singleton hosted within A. B is responsible for dynamically loading classes X, Y, and Z.
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 { public bool updated; public myTreeNode() {
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.