-->
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: Mapping single table with many FK ref to another table
PostPosted: Sat Sep 26, 2009 9:40 pm 
Newbie

Joined: Sat Sep 26, 2009 9:12 pm
Posts: 2
I have a table that contains contacts (think people) and another table that contains information about a system and who is responsible for aspects of the system (think owner, project manager, sys admin, etc)

Each system row has a column for each designated responsibility which holds a Foreign Key reference to the contact tables Primary Key that represents the appropriate contact (again, think person).

Here is a snipped from the POJO for my System bean (called SIP) representing the mappings for each person who has some responsibility to the system.

<snip>

Code:
@ManyToOne
@JoinColumn(name = "CONTACTID")
private Contact pm;
@ManyToOne
@JoinColumn(name = "CONTACTID")
private Contact iam;
@ManyToOne
@JoinColumn(name = "CONTACTID")
private Contact userRep;
@ManyToOne
@JoinColumn(name = "CONTACTID")
private Contact ca;


</snip>

I get the following error when I attempt to run the code:

Repeated column in mapping for entity: diacap.db.beans.SIP column: CONTACTID (should be mapped with insert="false" update="false")


I am new to hibernate but I imagine from what I read, if I "insert="false" update="false"", I will not be able to change the contacts. Is there some other pattern I should be following to accomplish my goal of storing multiple contact references in the same table but keeping the values mutable?

Thanks,

Thomas


Top
 Profile  
 
 Post subject: Re: Mapping single table with many FK ref to another table
PostPosted: Sun Sep 27, 2009 11:30 am 
Newbie

Joined: Sat Sep 26, 2009 9:12 pm
Posts: 2
Easy answer.

It is possible to provide more than one mapping for a particular persistent class. In this case, you must specify an entity name to disambiguate between instances of the two mapped entities. By default, the entity name is the same as the class name. Hibernate lets you specify the entity name when working with persistent objects, when writing queries, or when mapping associations to the named entity.

Now I just need to figure out how to do this with annotations - if I can.

Thomas


Top
 Profile  
 
 Post subject: Re: Mapping single table with many FK ref to another table
PostPosted: Tue Apr 13, 2010 6:41 am 
Newbie

Joined: Wed Jan 17, 2007 9:17 am
Posts: 3
I have the same problem. How did you solved this?

thanks


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.