|
[b]Hibernate version: 1.2[/b]
Hello,
I have a class with the following Property relationships (each property is itself a class, except the last one ("ValueInTable") which is a string type):
MainClass.Property1.Property2.ValueInTable
There is no inheritance between the classes and the final property in the chain "ValueInTable" is the property I'm trying to access/load via the mapping file and it is in the same table as all the other properties in the MainClass object.
The following mapping using Component works just fine for inserting and retrieving data:
<component name="Property1" class="Class1">
<component name="Property2" class="Class2">
<property name="ValueInTable" column="ColumnName"/>
</component>
</component>
My problem is that when accessing/setting the "ValueInTable", one of the classes up the chain (Class1) needs to be instantiated BEFORE actually setting "ValueInTable" (this is because I have some other parameters necessary that I pass in through the higher level class's declaration of the Class2 object via the constructor) -- in other words, I'd prefer to access the "ValueInTable" ONLY through the default constructor for Class2 called from Class1 (the instance of Class2 is actually set as a private member in Class1 and uses the default constructor with parameters for Class2). However, the above mapping directly sets the "ValueInTable" from the database without instantiating Class1 (hence, the private member variable for Class2 never gets it's default constructor called).
Is there a way to alter the above mapping to force accessing "ValueInTable" only AFTER the higher-level classes in the chain (Class1 -> Class2) have been instantiated? I've tried several options and at the moment I'm trying to use the "access:ClassName" strategy - but I've never created a custom PropertyAccessor before and don't know how. Is there an nHibernate way to do this?
Thanks.
|