I'm having an issue where I'm trying to map a private member of a
class which happens to have a non-virtual public setter Property. I
noticed that even if I set the access="field" attribute in the
property tag in the mappings file, as long as NHibernate sees my
public setter property, it gives an InvalidProxyTypeException. If i
make my setter property private or virtual public, then everything
works as planned.
I'm curious though, isn't NHibernate supposed to ignore properties if
I specify access="field"? I also tried nosetter and got the same
behavior. Also tried specifying the name strategy and same result.
Code snippets below:
Mapping:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="DomainModel" namespace="DomainModel">
<class name="Test" table="test" lazy="true" proxy="Test">
<id name="id" column="id" type="int" access="field.lowercase-underscore">
<generator class="sequence">
<param name="sequence">test_id_seq</param>
</generator>
</id>
<property name="_problematicfield" column="problematicfield"
type="string" length="50" access="field" not-null="true" />
</class>
</hibernate-mapping>
Class:
public class Test
{
public Test () {}
private int _id;
private string _problematicfield;
public string ProblematicField
{
set
{
_problematicfield =DoSomethingInteresting(value);
}
}
}
--
------------------------------------------------------------------
Enrique Ramirez Irizarry
Lead Developer, CodaBytes Consulting Group
http://www.Codabytes.com
Personal Page: http://www.indiecodelabs.com
After putting some thought into it, this class will be a foreign key
to the "workhorse" class. So you do have a point in that removing lazy
load is not a good solution in the long run. The reason why I didn't
want the setter method to be virtual was because it calculates values
for other private fields, and I was calling it in one of the class
constructors. I guess I could make a helper method to provide this
functionality and be able to place it in both the constructor and the
virtual setter.
Unless I'm missing something I think that's my only option.
Ah, of course. I should have thought of that two days ago. Thanks again!