-->
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: Reference to object from object
PostPosted: Wed Feb 18, 2009 6:03 pm 
Newbie

Joined: Wed Feb 18, 2009 5:36 pm
Posts: 1
Hi,

I'm looking for a best practice to design my domain model and sharply, to design object associations.


My domain model is quite complex (more than 150 objects). At first sight, when I need to add to object A an association to object B, I add a property to A of type B.

A
{
B b;
}

But, sometimes, when B and A are not in the same package, I would like to reduce dependency. Therefore, I would go to :

A
{
int bId; <-- integer to identity of B
}

Is it a good practice ? Do I keep full B?

Last but not least, If I choose this strategy and if I want to get a list of Products (which are linked to category), and can I write a Find Method where the grid gives me Products details and Category Name. Not easy because A contains only Id to B, not details. So, do I need to find each category ?

Hope you can help me !

Thks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 1:32 am 
Expert
Expert

Joined: Fri Jan 30, 2009 1:47 am
Posts: 292
Location: Bangalore, India
If you just keep the foreign key in the associated class and not the whole B then I think you wont be able to utilize the hibernate association features.

jeybonnet wrote:
But, sometimes, when B and A are not in the same package, I would like to reduce dependency

I think, if A is associated to B then there IS a dependency between the two classes which means the package also need to be dependent or put both the classes in same package. You have to make either of the above decisions rather than avoiding the code dependency when the dependency is there in your business model.

jeybonnet wrote:
Is it a good practice ? Do I keep full B?

So I think you should be keeping the full B

jeybonnet wrote:
Last but not least, If I choose this strategy and if I want to get a list of Products (which are linked to category), and can I write a Find Method where the grid gives me Products details and Category Name. Not easy because A contains only Id to B, not details. So, do I need to find each category ?

Yes you can always write the find method. But as you said this wont be straight forward. You will have to issue an join HQL for getting the Category name of a Product.

_________________
Regards,
Litty Preeth


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 5:46 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
I agree with littypreethkr: Even if you replace your B with the id of B, it is a dependency, not directly but the value of your foreign key depends on B, so you have a kind of transitive dependency.
The difference is, that in that case, you have to manage all associations by yourself instead of letting an or-mapper do it for you. So why not keeping B in A with all the nice features of an or-mapper, like transitive persistence and so on.

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


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.