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.  [ 2 posts ] 
Author Message
 Post subject: Creating Java Associations vs. Using finders methods.
PostPosted: Mon Jan 23, 2006 12:04 am 
Newbie

Joined: Sun Jan 22, 2006 11:32 pm
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

I have question. First, I have two objects A and B that have a one-to-many association from A to B and many-to-one from B to A. Is it appropriate to have a physical Java Object association on only object B. For example B.setA(A) and not have A.getBs().add(B). This is similar to the many-to-one association of Item and Bid. If I wanted to to retrieve all B objects that are related to A (all Bids associated with an Item), I could just write a finder method that scans the B or Bid table looking for the Item foreign key. The plus side to this is that Items are not tightly coupled to Bids. I could use Item in another context unaware of Bids. If a given object, like Item has other one-to-many associations, it seems that it is physically burdened with unnecessary associations. Further it may not be easily reused in other context.

I ask this question because I am working on a project were one object has 2 one-to-many associations. If it were the case that the object needed the associations to be in a valid state (aggregates) then I guess I would think create both associations. To me Item can exist without Bid and therefore it is not mandatory to create the one-to-many association. Any advice or best practice regarding this problem would be greatly appreciated.

Thank you in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 23, 2006 3:34 am 
Regular
Regular

Joined: Tue Oct 26, 2004 3:54 pm
Posts: 60
I think you should declare all associations in your model, because they belong to the business object.

You can define an association "lazy" so that it will be fetched from the DB only if accessed, it that is what worries you.

Refer to Hibernate reference documentation about this.

Giulio


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