I have the following:
Code:
public class Product {
int productId;
//... other stuff
}
public class ProductFan : Product {
IList products; //list of ProductMap elements
//... other stuff
}
public class ProductMap {
Product parentProduct;
Product childProduct
//... other stuff
}
These are mapped as follows:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" default-access="field">
<class name="SpringAir.Objects.Product, SpringAir.Objects" table="Product">
<id name="productId" type="Int32" column="ProductId" unsaved-value="-1">
<generator class="hilo">
<param name="table">IdGenerator</param>
<param name="column">NextProductId</param>
<param name="max_lo">0</param>
</generator>
</id>
</class>
<joined-subclass name="SpringAir.Objects.ProductFan, SpringAir.Objects" table="ProductFan" extends="SpringAir.Objects.Product, SpringAir.Objects">
<key column="ProductId" />
<bag name="products" table="ProductMap" cascade="all" lazy="true">
<key column="ProductId" />
<composite-element class="SpringAir.Objects.ProductMap, SpringAir.Objects">
<parent name="parentProduct" /> <!--THIS CAUSES AN ERROR!!-->
<property name="sequenceNumber" column="SequenceNumber" />
<many-to-one name="childProduct" column="ChildProductId" not-null="true" />
</composite-element>
</bag>
</joined-subclass>
</hibernate-mapping>
I originally had ProductMap as its own entity, but really it's lifecycle is tied to the parentProduct, so it's now a component. Unfortunately, the parent definition under the composite-element triggers the following exception when building the session factory:
Code:
[PropertyNotFoundException: Could not find a setter for property 'parentProduct' in class 'SpringAir.Objects.ProductMap']
NHibernate.Property.BasicPropertyAccessor.GetSetter(Type type, String propertyName)
NHibernate.Type.ComponentType..ctor(Type componentClass, String[] propertyNames, IGetter[] propertyGetters, ISetter[] propertySetters, Boolean foundCustomAcessor, IType[] propertyTypes, OuterJoinFetchStrategy[] joinedFetch, CascadeStyle[] cascade, String parentProperty) +313
NHibernate.Cfg.Binder.BindComponent(XmlNode node, Component model, Type reflectedClass, String className, String path, Boolean isNullable, Mappings mappings) +3299
NHibernate.Cfg.Binder.BindCollectionSecondPass(XmlNode node, Collection model, IDictionary persistentClasses, Mappings mappings) +1351
NHibernate.Cfg.CollectionSecondPass.SecondPass(IDictionary persistentClasses) +21
NHibernate.Cfg.AbstractSecondPass.DoSecondPass(IDictionary persistentClasses) +100
NHibernate.Cfg.Configuration.SecondPassCompile() +124
NHibernate.Cfg.Configuration.BuildSessionFactory() +12
The session factor loads fine without the parent definition, but there is some code that uses parentProduct, so I'd like to get it working. It seems it can't find the setter. Is it looking for a propery rather than a field? I have specified field-level access, so I'm not sure what the problem might be. Any thoughts?