-->
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.  [ 1 post ] 
Author Message
 Post subject: Optimal mapping strategy for multiple one-to-many
PostPosted: Fri May 28, 2010 8:03 am 
Beginner
Beginner

Joined: Sun Oct 03, 2004 8:50 am
Posts: 32
Location: McLean, VA
I'd like to get people's opinion on the optimal way to map the following:

I have an entity "App" and an entity "Group". A group belongs to an app (that is, it's a many groups to one app relationship). An app can have many groups. An app can also have a list of default groups. So the App entity has two one-to-many relationships with Group, the App/Owned-Groups relationship and the App/Default-Groups relationship. The former needs to be bidirectional.

The option I have working now is:
- create a many-to-one relationship on Group to App
- create a one-to-many relationship on App to Group and marked it as mapped by Group (this being the inverse of the previous relationship)
- create a one-to-many relationship on App to Group to track the default groups

Code:
@Entity
public class Group {

   @ManyToOne
   private App app;

}

@Entity
public class App {

   @OneToMany(mappedBy="app")
   private List<Groups> groups;

   @OneToMany
   private List<Group> defaultGroups;
}


As I said, this works now but I end up with a join table tracking the default groups. Is there a method whereby I can put the "this is a default group" flag on the Group entity itself and adjust the two relationships in App such that the defaultGroups property only contains the Group entities where isDefaultGroup==true? Would doing so result in less traffic to the database? Would Hibernate make only a single query to the Group table and then populate both collections from the retrieved data?

Thanks.

_________________
- Chad


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

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.