When a <property/> maps to a property of type System.Object, a MappingException is thrown with the message:
Quote:
"property mapping has wrong number of columns: SillyClass.UntypedPropertyConfusesMapping.SillyClass type: Object"
Reproduce with the following mapping/class snippets. I specificaly post this in vb.net because it is very easy to forget to include a type at the end of a property decleration.
SillyClass.vb:
Code:
Public Class SillyClass
Private _good As Integer
Private _bad As Integer
Public Property Good() As Integer
Get
Return _good
End Get
Set(ByVal value As Integer)
_good = value
End Set
End Property
Public Property Bad() 'whoops, forget "As Integer"
Get
Return _bad
End Get
Set(ByVal value)
_bad = value
End Set
End Property
End Class
SillyClass.hbm.xml:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
xmlns="urn:nhibernate-mapping-2.2"
assembly="UntypedPropertyConfusesMapping"
namespace="UntypedPropertyConfusesMapping">
<class name="SillyClass" table="SillyTable">
<id name="Good" column="good">
<generator class="assigned" />
</id>
<property name="Bad" column="bad" />
</class>
</hibernate-mapping>
Based on the exception message, it is very difficult to determine the actual cause of the problem. A better exception might include:
- The property name, either from the mapping file or the class
- That the 'object' type is not valid.
Comments? Should I add this as a bug in JIRA? Thanks!
Nick