-->
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: Do you bother to map every association?
PostPosted: Tue Nov 24, 2009 3:32 am 
Newbie

Joined: Tue Nov 24, 2009 3:07 am
Posts: 2
Hi Everyone,

Please consider the following. You have a Person and they have a Company attribute which could be mapped as a many-to-one association. That is in the Person table there is a field CompanyId and is the foreign key of CompanyId in the Company table.

Do you bother to map all associations like this bearing in mind you will not be doing any queries of Persons based on Company name etc. You will only be using the id of the company when deaing with Persons. The reason I ask is that if the association is mapped there will be an extra lookup everytime the Person is created or updated because you need to look up the Company and then set it in the Person. I could just leave the Company field of Person as a Long which is mapped to the CompanyId field in the Person Table.

Or am I being too concerned about possible performance issues.

What does everyone else do? Map all associations by default and remove any later that are performance problems and not required by the application?

Cheers,
Loska.


Top
 Profile  
 
 Post subject: Re: Do you bother to map every association?
PostPosted: Tue Nov 24, 2009 4:25 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
loska wrote:
The reason I ask is that if the association is mapped there will be an extra lookup everytime the Person is created or updated because you need to look up the Company and then set it in the Person. I could just leave the Company field of Person as a Long which is mapped to the CompanyId field in the Person Table.

You don't have to do the extra lookup if you are sure that a company with a certain id exists. You could use session.load() or entitymanager.getReference(). These methods return a proxy without querying the database.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: Do you bother to map every association?
PostPosted: Tue Nov 24, 2009 5:06 am 
Newbie

Joined: Tue Nov 24, 2009 3:07 am
Posts: 2
Thanks mmerder,

That makes perfect sense and now my question seems rather stupid. RTFM!


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.