ORM(Object Relational Mapping)을 이해한다.

Goal

  • 영속성(Persistence)이란
  • ORM(Object Relational Mapping)이란
  • ORM의 장단점
  • The Object-Relational Impedance Mismatch
  • Association(연관성)
    • One-To-One Relationship
    • One-To-Many Relationship

영속성(Persistence)

ORM이란

Object Relational Mapping, 객체-관계 매핑

ORM의 장단점

The Object-Relational Impedance Mismatch

Association(연관성)

  1. One-To-One Relationship
    • 예를 들어, 각 학생은 고유한 주소를 가지고 있다고 하자.
    • RDBMS (방향성이 없다.)
      • 각 Student의 record는 서로 다른 Address record를 가리키고 이것은 일대일 매핑을 보여준다.
    • Java Object (방향성이 있다.)
      public class Student {
       private long studentId;
       private String studentName;
       private Address studentAddress; // Student -> Address
       
      }
      public class Address {
       private long addressId;
       private String street;
       private String city;
       private String state;
       private String zipcode;
       
      }
      
  2. One-To-Many Relationship
    • 예를 들어, 각 학생은 여러 개의 핸드폰을 가질 수 있다고 하자.
    • RDBMS (방향성이 없다.)
      • 각 Student의 record는 여러 개의 Phone record를 가리킬 수 있다. (일대다 매핑)
      • 이 관계를 하나의 다른 Table(Relational Model)로 만들 수 있다.
      • One-To-Many를 구성하는 방법: 1) Join Table, 2) Join Column
    • Java Object (방향성이 있다.)
      public class Student {
       private long studentId;
       private String studentName;
       private Set<Phone> studentPhoneNumbers; // Student -> Some Phones
       
      }
      public class Phone {
       private long phoneId;
       private String phoneType;
       private String phoneNumber;
       
      }
      

관련된 Post

References