Basic Mapping:

Advance Mappings
- In the database you most likely will have
- Multiple tables
- Relationships between Tables
- Need to model this with Hibernate
Advanced Mappings Type
- One-to-One
- One-to-Many, Many-to-One
- Many-to-Many



Important Database Concepts
- Primary key and foreign key
- Cascade
Primary Key and Foreign Key
- Primary Key: identify a unique row in a table
- Foreign Key:
- Link tables together
- A field in one table that refers to primary key in another table

Cascade
- You can cascade operations
- Apply the same operation to related entities
- Whenever an object will be saved in the table “instructor” then simultaneously the object will also be saved within another table “instruction_details”.

- If we delete an instructor, we should also delete their instructor_detail.
- This is known as ” CASCADE DELETE “


Note: We should not perform cascade deletion operation in Many-to-Many mapping.
Fetch Types: Eager vs Lazy Loading
- When we fetch / retrieve data, should we retrieve EVERYTHING?
- Eager will retrieve everything in a single shot
- Lazy will retrieve on request
Uni-Directional Relationship
- Is a one way relationship
- You have an “instructor” and then you have “instructor_detail”, so you will start with instructor object you load the instructor and then from there access the instructor detail.

Bi-Directional Relationship
- Instructor and then they have its relation with instructor detail, but then also we can go the other way. So we can load the instructor details and have a reference to the instructor.
