-->
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.  [ 4 posts ] 
Author Message
 Post subject: Error: Getting a mapping hibernate exception
PostPosted: Mon Jan 11, 2010 12:15 am 
Newbie

Joined: Sun Jan 10, 2010 11:49 pm
Posts: 2
I have 3 tables:

UserGoals.
This has a composite key:
idPatient
idGoalTypes
idGolas

GoalType
Key: idGoalType
other column: GoalType

Goals
Key:idGoals
other column:Goal


my schema.hbm.xml file

<class name="hci.weblog.model.UserGoals" table="UserGoals">
<composite-id>
<key-property name="idPatient" column="idPatient" type="integer"/>
<key-property name="idGoalType" column="idGoalType" type="integer"/>
<key-property name="idGoals" column="idGoals" type="integer"/>
</composite-id>

<set name="GoalType" sort="hci.weblog.model.GoalType" table="GoalType" inverse="true" lazy="false" cascade="none">
<key column="idGoalType"/>
<one-to-many class="hci.weblog.model.GoalType" />
</set>
<set name="Goals" sort="hci.weblog.model.Goals" table="Goals" inverse="true" lazy="false" cascade="none">
<key column="idGoals"/>
<one-to-many class="hci.weblog.model.Goals" />
</set>

</class>



<class name="hci.weblog.model.GoalType" table="GoalType">
<id name="idGoalType" column="idGoalType" type="integer"/>
<property name="GoalType" column="GoalType" type="string"/>
</class>

<class name="hci.weblog.model.Goals" table="Goals">
<id name="idGoals" column="idGoals" type="integer"/>
<property name="Goal" column="Goal" type="string"/>
</class>


I am getting the error:
Foreign key (FK6AE7250DE285619A:GoalType [idGoalType])) must have same number of columns as the referenced primary key (UserGoals [idPatient,idGoalType,idGoals])

Can't figure out what needs to be changed in this mapping ? Would it help if instead of having a composite key in usergoal table, I add a auto generated primary key instead?

Any help would be appreciated.

Thanks
Ruby

Would it help if I make


Top
 Profile  
 
 Post subject: Re: Error: Getting a mapping hibernate exception
PostPosted: Mon Jan 11, 2010 1:30 am 
Beginner
Beginner

Joined: Wed Jun 17, 2009 9:03 pm
Posts: 31
Location: mumbai
Hi

I guess you need to specify all the column in composite key in your key column.

Code:


<class name="hci.weblog.model.UserGoals" table="UserGoals">
<composite-id>
<key-property name="idPatient" column="idPatient" type="integer"/>
<key-property name="idGoalType" column="idGoalType" type="integer"/>
<key-property name="idGoals" column="idGoals" type="integer"/>
</composite-id>

<set name="GoalType" sort="hci.weblog.model.GoalType" table="GoalType" inverse="true" lazy="false" cascade="none">
   <key>
   <column="idPatient"/>
   <column="idGoalType"/>
   <column="idGoals"/>
</key>
<one-to-many class="hci.weblog.model.GoalType" />
</set>
<set name="Goals" sort="hci.weblog.model.Goals" table="Goals" inverse="true" lazy="false" cascade="none">
<key>
   <column="idPatient"/>
   <column="idGoalType"/>
   <column="idGoals"/>
</key>
<one-to-many class="hci.weblog.model.Goals" />
</set>

</class>



In case of not using composite key your mapping will work.


Top
 Profile  
 
 Post subject: Re: Error: Getting a mapping hibernate exception
PostPosted: Mon Jan 11, 2010 2:38 pm 
Newbie

Joined: Sun Jan 10, 2010 11:49 pm
Posts: 2
Hey thanks.

Tried it the way you mention.
Get an error which says :


Fatal Error: Element Type column must be followed by either attribute specifications, ">" or "/>".

[
<set name="GoalType" sort="hci.weblog.model.GoalType" table="GoalType" inverse="true" lazy="false" cascade="none">
<key>
? <column="idPatient"/>

Error is in the line with question mark.
]

And I made sure it correct syntax wise. Its exactly the same mapping as you have specified.


Top
 Profile  
 
 Post subject: Re: Error: Getting a mapping hibernate exception
PostPosted: Mon Jan 11, 2010 10:05 pm 
Beginner
Beginner

Joined: Wed Jun 17, 2009 9:03 pm
Posts: 31
Location: mumbai
Hi

Please try like this.

Code:
<set name="GoalType" sort="hci.weblog.model.GoalType" table="GoalType" inverse="true" lazy="false" cascade="none">
   <key>
   <column name= "idPatient"/>
   <column name = "idGoalType"/>
   <column name ="idGoals"/>
</key>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.