-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem mapping one-to-many relationship and composite-id
PostPosted: Fri Dec 02, 2011 4:29 am 
Newbie

Joined: Fri Dec 02, 2011 4:12 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.