-->
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: Mapping Two One-To-One associations with the same type
PostPosted: Wed May 30, 2007 11:38 am 
Newbie

Joined: Fri Dec 29, 2006 12:20 pm
Posts: 8
Hi

I have a User that has two Folders, SentFolder and SavedFolder. How can I map the associations?

Is this correct?

Code:
public class Folder {
    @OneToOne(cascade = CascadeType.MERGE)
    private User user;
}

public class User {
    @OneToOne(mappedBy = "user")
    protected Folder sentFolder;
    @OneToOne(mappedBy = "user")
    protected Folder savedFolder;
}


This approach is not correct, because both of the associations is mapped via just one foreign key.

_________________
--
REZA++


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 12:38 pm 
Newbie

Joined: Sun Sep 11, 2005 7:46 pm
Posts: 15
How about try to make two subclasses of the Folder class, let's call them SentFolder and SavedFolder. So the cardinality between SentFolder and User is OneToOne and the cardinality between SavedFolder and User is also OneToOne. You can then add their references into the User class.


Top
 Profile  
 
 Post subject: Yes, But ...
PostPosted: Wed May 30, 2007 12:52 pm 
Newbie

Joined: Fri Dec 29, 2006 12:20 pm
Posts: 8
I'm doing that now, but I thought this may not be a good answer. Cause I'm introducing new entities and classes into my domain just to solve my problem.

Still I'm searching for a better solution. Thanks anyway.

_________________
--
REZA++


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 2:19 pm 
Beginner
Beginner

Joined: Fri May 18, 2007 10:28 am
Posts: 48
Location: Madison, WI
These are value types and not entities. Entities are something that you physically map to a table.


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.