Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

my understanding of hibernate is correct ?

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After reading the tutorial and browsing this great forum, I have some notes below. I am not sure if my understanding is correct ? Anything wrong, please correct me.

My goal is to simplify relationship and easily operational, based on real world java programming.

/////////////////////////////////////////////////////////////
1. one-to-one
class User{
Address myAddress;
}
option 1: use component //easy , ignore here
option 2: one-to-one //easy , ignore here


2. one-to-many
class Parent{
Child[] myChild;
}
Option1:
if it is one-way-direction (only parent knows his child,child doesn't know parent)
<set>
.....
<one-to-many>
</set>

Option 2:
if it is both-way direction (trace each other), parent/child
######## in the parent mapping ############
<set name="children" inverse="true" cascade="all">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>

########## in the child mapping ###########
<many-to-one name="parent" column="parent_id" not-null="true"/>
###########################################

3. many-to-one
actually it is bundled with one-to-many. See the child mapping.

4. many-to-many
We don't need to think about many-to-many, because in the database design,
the many-to-many is not allowed. As you know, we always break a many-to-many relationship
into one-to-many or many-to-many. So ignore this relationship
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic