-->
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.  [ 3 posts ] 
Author Message
 Post subject: need help with composite-id question.
PostPosted: Wed Oct 24, 2007 2:04 pm 
Newbie

Joined: Fri Jan 26, 2007 10:37 am
Posts: 6
Greetings:

I am stuck with a mapping issue I am hoping someone here has seen before. I don't think it is that complicated but I can not understand what to do based on the documentation I've read so far.

I have 3 classes: Survey, Question and SurveyQuestion. These each map to their own table in the db. The SurveyQuestion class holds a Survey and Question object. The composite key of the SurveyQuestion table is the sid from the Survey object, the qid from the Question object and the additional date.

Does anyone know how to map this relationship in the SurveyQuestion mapping? The mapping I currently use gives the exception below. from the trace of the exception, it is obvious that key-properties cannot be used like property-ref attributes.

Any help or advice is greatly appreciated.

Hibernate version:
3.2.1.ga

Name and version of the database you are using:
mysql 5.

Mapping documents:
<class name="com.beans.Survey" table="survey">
<id name="sid" column="sid" type="int" />

<property name="name" type="java.lang.String" column="name" />
</class>

<class name="com.beans.Question" table="question">
<id name="qid" column="qid" type="int" />

<property name="question" type="java.lang.String" column="question" />
</class>

<class name="com.beans.SurveyQuestion" table="survey_question">
<composite-id>
<key-property name="survey.sid" type="int" column="sid" />
<key-property name="question.qid" type="int" column="qid" />
<key-property name="when" type="timestamp" column="when" />
</composite-id>

<component name="survey" class="com.beans.Survey" />
<component name="question" class="com.beans.Question" />

</class>



Full stack trace of any exception that occurs:
nested exception is org.hibernate.PropertyNotFoundException: Could not find a getter for survey.sid in class com.b
eans.SurveyQuestion
Caused by:
org.hibernate.PropertyNotFoundException: Could not find a getter for survey.sid in class com.beans.SurveyQuestion
at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:282)
at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:275)
at org.hibernate.mapping.Property.getGetter(Property.java:272)
at org.hibernate.tuple.component.PojoComponentTuplizer.buildGetter(PojoComponentTuplizer.java:130)
at org.hibernate.tuple.component.AbstractComponentTuplizer.<init>(AbstractComponentTuplizer.java:43)
at org.hibernate.tuple.component.PojoComponentTuplizer.<init>(PojoComponentTuplizer.java:38)
at org.hibernate.tuple.component.ComponentEntityModeToTuplizerMapping.<init>(ComponentEntityModeToTuplizerMapping.java:52)
at org.hibernate.tuple.component.ComponentMetamodel.<init>(ComponentMetamodel.java:50)
at org.hibernate.mapping.Component.buildType(Component.java:152)
at org.hibernate.mapping.Component.getType(Component.java:145)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.RootClass.validate(RootClass.java:193)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1099)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1284)
...


Thanks.
Bill.
....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 24, 2007 4:18 pm 
Newbie

Joined: Mon Apr 30, 2007 12:27 pm
Posts: 18
I dont know if this can help you, but I dont think you are supposed to map the key-properties like that, with the not notation.

<key-property name="survey.sid" type="int" column="sid" />

I dont think that hibernate navegates through one object to the next.

From the exception it is seems that hibernate is looking for a property called "survey.sid "in class com.beans.SurveyQuestion, which obviously isnt there.

Can you post your classes as well?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 24, 2007 4:20 pm 
Newbie

Joined: Mon Apr 30, 2007 12:27 pm
Posts: 18
I almost forget, this link may help you:
http://www.theserverside.com/discussions/thread.tss?thread_id=22638


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

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.