-->
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: Where is the best place(s) to handle entity relationships?
PostPosted: Tue Apr 13, 2004 10:41 am 
Beginner
Beginner

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 20
Hi,

I've been searching and reading posts and articles around this website, tring to decide whether I should implement all the relationship handling into my DAO or leave it to the business logic layer.

By relationship handling, I mean calling the stuff like addChild(), add Parent(), and deleteChild() etc.

My feeling is to include these in the DAO layer, because the associated objects are initialized (lazy or not) anyway through a single DAO method call.

But when considering things like a composition relationship, questions like "should I create the child from within the parent creation code?" got me into lost:

    1. If I do create children in the parent creation code, then the ParentDAO should know about childDAO, which may lead to a very complicated DAO structure;
    2. If I leave the child creation to the business logic, then the business logic will be required to know all the data manipulation details, which ideally should be hidden behind the DAO layer.

Any comments/suggestions?

Thanks,
Dan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 15, 2004 7:17 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I recommend handling relationships in additional methods in the domain model POJOs themself:

Code:
public void addChildCategory(Category childCategory) {
    if (childCategory == null)
        throw new IllegalArgumentException("Can't add a null child category.");
    if (childCategory.getParent() != null)
        childCategory.getParent().getChildCategories().remove(childCategory);
    childCategory.setParent(this);
    childCategories.add(childCategory);
}

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 15, 2004 10:25 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what about putting this usefull approach as a best pratice in the reference doc or wiki?

i even think that depending mapping (one to


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.