I have a parent class containing an listChilds object which contains List of Child elements, there is a foreign key from child table to parent table (parent_id), but Child class does not have a parent_id field, I tried with this mapping:
Code:
<class name="Parent" table="parent" lazy="false">
<component name="listChilds">
<bag name="child" cascade="all">
<key column="parent_id" not-null="true"/>
<one-to-many class="Child"/>
</bag>
</component>
</class>
<class name="Child" table="child" lazy="false">
<composite-id>
<key-property name="parent_id" column="parent_id"/>
<key-property name="field1"/>
</composite-id>
</class>
but hibernate throws the exception org.hibernate.PropertyNotFoundException: field [parent_id] not found on Child
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:145)
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:137)
at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:160)
at org.hibernate.util.ReflectHelper.getter(ReflectHelper.java:241)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:229)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:302)
at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2193)
at org.hibernate.cfg.HbmBinder.bindComponent(HbmBinder.java:1922)
at org.hibernate.cfg.HbmBinder.bindCompositeId(HbmBinder.java:1745)
at org.hibernate.cfg.HbmBinder.bindCompositeId(HbmBinder.java:446)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:360)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:295)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:166)
at org.hibernate.cfg.Configuration.add(Configuration.java:716)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:551)
...
The parent_id and field1 combination must be unique, i cannot modify any of the classes because they are generated automatically, how can i map this?
Thanks