• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

my understanding of hibernate is correct ?

 
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
 
A "dutch baby" is not a baby. But this tiny ad is baby sized:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic