Click here to Skip to main content
15,881,652 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I am trying to implement NHibernate 3.2.2 updating application coded originally written with NHibernate 1.2.1. Needless to say, I have needed to make a number of changes just to successful ly compile the code. I am now stuck with the following exception that occurs when I attempt to read any list from the database:
Exception occurred getter of Business.PersistableEntityBase.ObjectID
The inner exception is:  Object does not match target type.

The really odd thing is that the class in question, the PersistableEntityBase, was never been mapped for nHibernate in an xxxx.hbm.xml file because it is an abstract class used as the base class for all of the objects we are persisting with NHibernate.

Here is the class:
C#
[Serializable]
public abstract class PersistableEntityBase
{
    public Guid ObjectID { get; set; }
    public int Version { get; set; }
}

From my research, it seemed that the newer version of NHibernate required that I create a mapping for this class so I added the following:

XML
<?xml version="1.0" encoding="utf-8" ?>
 
<hibernate-mapping
	xmlns="urn:nhibernate-mapping-2.2"
	assembly="Business"
	namespace="Business">
 
	<class name="PersistableEntityBase" abstract="true" >
 
		<id
			name="ObjectID"
			column="objectID"
			type="Guid">
 
			<generator class="guid.comb" />
		</id>
 
		<version
			name="Version"
			column="version"
			type="Int32" />
 
	</class>
</hibernate-mapping>


After adding the above mapping file, I got the following exception as soon as I attempt to run the app:

"The following types may not be used as proxies:
\Business.PersistableEntityBase: method get_ObjectID should be 'public/protected virtual' or 'protected internal virtual'
\Business.PersistableEntityBase: method set_ObjectID should be 'public/protected virtual' or 'protected internal virtual'
\Business.PersistableEntityBase: method get_Version should be 'public/protected virtual' or 'protected internal virtual'
\Business.PersistableEntityBase: method set_Version should be 'public/protected virtual' or 'protected internal virtual'

After adding the modifers indicated by the exception, the application would successfully start up, but now when I run the list page, I again receive the original exception:
Exception occurred getter of Business.PersistableEntityBase.ObjectID
The inner exception is:  Object does not match target type.

Any help would be greatly appreciated
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900