-->
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.  [ 5 posts ] 
Author Message
 Post subject: Is it necessary to map relationships on both sides?
PostPosted: Thu May 13, 2004 8:24 am 
Beginner
Beginner

Joined: Wed May 12, 2004 2:52 pm
Posts: 36
Given the following tables:

User
----------
userId (PK)
userName
roleId (FK)

Role
----------
roleId (PK)
roleName

When using middlegen, I found that it generates the following classes:

User
----------
long userId
String userName
Role role

Role
----------
long roleId
String roleName
Set users

Is there a reason why the "Role" class maintains a Set of users or is this an unnecessary artifact from code generation (Read: can I delete it?)? Role is simply a look up table. I don't see the need to keep a reference back to every user. Does Hibernate use this for caching?

Regards,

Joshua


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 9:02 am 
Newbie

Joined: Wed May 12, 2004 5:12 pm
Posts: 8
Location: Frankfurt / Germany
I doubt hibernate would need that for caching.
In my eyes this is an absolutley correct behaviour as you might want to view all the users that have a certain role.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 9:23 am 
Beginner
Beginner

Joined: Wed May 12, 2004 2:52 pm
Posts: 36
I tend to agree.

Any comments from the Hibernate team?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 1:32 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You can have that either bidirectional or uni-directional, what you see is just a default.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 9:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Middlegen shows (in the GUI) if the relationship is uni- or bi-directional. You can change it if you want it to go only one direction. The default is to make it bi-directional.


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