Advanced Java (2160707)

BE | Semester-4   Winter-2018 | 20-11-2018

Q4) (c)

What is ORM? Explain object/relational mappings in hibernate

Object-Relational Mapping

  • It is a programming technique for converting object-type data of an object oriented programming language into database tables.
  • Hibernate is used to convert object data in JAVA to relational database tables.

Hibernate O/R Mapping

  • Three most important mapping are as follows:
    1. Collections Mappings
    2. Association Mappings
    3. Component Mappings
  1. Collections Mapping
    • If an entity or class has collection of values for a particular variable, then we can map those values using any one of the collection interfaces available in java.
    • Hibernate can persist instances of java.util.Map, java.util.Set, java.util.SortedMap, java.util.SortedSet, java.util.List, and any array of persistent entities or values.
    • Collections Mapping
      (Figure: Collections Mapping)
  2. Association Mappings
    • The mapping of associations between entity classes and the relationships between tables is the soul of ORM.
    • There are the four ways in which the cardinality of the relationship between the objects can be expressed.
    • An association mapping can be unidirectional as well as bidirectional.
    • Association Mappings
      (Figure: Association Mappings)
  3. Component Mappings:
    • If the referred class does not have it's own life cycle and completely depends on the life cycle of the owning entity class, then the referred class hence therefore is called as the Component class.
    • The mapping of Collection of Components is also possible in a similar way just as the mapping of regular Collections with minor configuration differences.