-->
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.  [ 8 posts ] 
Author Message
 Post subject: Category Mapping Question
PostPosted: Sat Dec 16, 2006 8:50 pm 
Newbie

Joined: Wed Nov 30, 2005 4:40 pm
Posts: 14
Location: St. Louis MO.
I am confused about the Category.java class @ 3.2.4. Why does it Have a Category instance variable itself? I understand it having the Set for for sub-categories, but isn't "this" sufficient for a Category to know about itself?

Scott


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 4:29 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The instance variable has the name "parentCategory". This is a reference to another instance of Category, the "parent". This is a hierarchy of categories.

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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 11:34 am 
Newbie

Joined: Wed Nov 30, 2005 4:40 pm
Posts: 14
Location: St. Louis MO.
Christian --

Do you ever sleep? I get better customer support from you than I do with IBM! Okay bra, let me ask my question another way. Consider the class below:


class Category {

private Long id;
private Set children;

}

This code allows me to treat the 1-n self-association without the Category instance variable.

Peace,
Scott


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 1:21 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Bad idea. The parentCategory reference is a direct pointer-representation of the foreign key column in the database schema. It's good to have that. I repeat this several times in the book: Map all foreign keys to many-to-one associations. Then make these associations bidirectional (with a collection) if you _have_ to. Not just because you feel like it.

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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 3:16 pm 
Newbie

Joined: Wed Nov 30, 2005 4:40 pm
Posts: 14
Location: St. Louis MO.
What about the scenario where I am not saving the self-association? Why would the self reference need to exist then?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 3:41 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
There is no "self" reference pointer. The "parentCategory" is a pointer that represents the PARENT_CATEGORY_ID foreign key column. This is a reference to a _different_ category, the parent of the current one.

Yes, the childCategories of this mysterious parent is a mapping of this very same foreign key. But it's not the same representation in Java.

Do you understand that the categories form a tree, a data structure that has some recursive properties?

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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 4:49 pm 
Newbie

Joined: Wed Nov 30, 2005 4:40 pm
Posts: 14
Location: St. Louis MO.
Thanks Christian! As soon as you you said "tree," I got it.

Is there a way to retrieve the most current eBook periodically? I'd rather not mess with the errata alongside my PDF.

Thanks again,
Scott


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 5:04 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
There are no regular updates to the ebook, maybe every half year when a new print run has to be done. I don't expect any major changes, minor errata only.

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


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