-->
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: Hibernate: Having table with 3 FK (all FK come from 1 table)
PostPosted: Thu Mar 13, 2008 10:49 pm 
Newbie

Joined: Thu Mar 13, 2008 10:40 pm
Posts: 3
Location: Philippines
Good Day!

I just couldn't find any solution to my problem in the internet and from the posted forums

I have two tables:
User and Tasks

Tasks has 3 foreign Keys (assignedBy, assignedTo, accomplishedBy)
which contain userId from the user table.

How can I map Tasks? Since the one below is not permitted to be contained in one file....

Code:
<many-to-one name="User" class="User" column="assignedBy"/>
</class>

<many-to-one name="User" class="User" column="assignedTo"/>
</class>

<many-to-one name="User" class="User" column="accomplishedBy"/>
</class>


Hopefully someone can help me.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 2:54 am 
Beginner
Beginner

Joined: Fri Jun 25, 2004 11:47 am
Posts: 34
You have named 3 times the different columns to the same property...
try:

Code:
<many-to-one name="assignedBy" class="User" column="assignedBy"/>
</class>

<many-to-one name="assignedTo" class="User" column="assignedTo"/>
</class>

<many-to-one name="accomplishedBy" class="User" column="accomplishedBy"/>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 3:36 am 
Newbie

Joined: Thu Mar 13, 2008 10:40 pm
Posts: 3
Location: Philippines
knoll wrote:
You have named 3 times the different columns to the same property...
try:

Code:
<many-to-one name="assignedBy" class="User" column="assignedBy"/>
</class>

<many-to-one name="assignedTo" class="User" column="assignedTo"/>
</class>

<many-to-one name="accomplishedBy" class="User" column="accomplishedBy"/>
</class>



the name attribute = should be the name of the attribute which is user
the class attribute = should be the class name of the attirbute so still User
the column attribute = should be the column name of your foreign key

so I dont understand why you want me to change the name to be the same as the column name since name should be the correponding name of the attribute


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 4:42 am 
Beginner
Beginner

Joined: Fri Jun 25, 2004 11:47 am
Posts: 34
the attribute 'name' is the property in your java class you want to map the column. In your original mapping, you map 3 times the same java property to different column (FK). This can't work...

You can choose whatever name you want for the value specified in attribute name.


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.