# darbyluv2code/hibernate-advanced-development-techniques architecture

> Architecture diagram of the GitHub repository darbyluv2code/hibernate-advanced-development-techniques, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/darbyluv2code/hibernate-advanced-development-techniques
- Repository: https://github.com/darbyluv2code/hibernate-advanced-development-techniques

## Overview

This project is a collection of sample applications demonstrating advanced Hibernate techniques, including mapping collections (sets, lists, maps, sorted sets, sorted maps), various inheritance mapping strategies (single table, table per class, joined, mapped superclass), and component mapping using enums. The purpose is to illustrate different Hibernate ORM mapping scenarios through multiple self-contained modules, each with its own Maven build (pom.xml) and configuration (hibernate.cfg.xml), along with accompanying SQL scripts.

##### Main Components
- Demo Modules – Each demo is a standalone Java application (for example, CreateStudentImagesSetDemo, CreateStudentImagesListDemo, CreateUserStudentInstructorDemo, CreateStudentAddressDemo, etc.). These modules represent individual use cases and mapping scenarios.
- Configuration Layer – Each module loads its own Hibernate configuration (hibernate.cfg.xml) and, in some cases, references corresponding SQL scripts. This layer is crucial for initializing the SessionFactory and managing database connections.
- Domain/Entity Layer – The domain entities, such as Student, Instructor, User, and Address, are at the heart of the demonstration. They are mapped with various strategies and collection types.
- Persistence Layer – Represent the Hibernate ORM framework itself that handles the mapping and persistence logic.
- Database – The underlying database accessed via Hibernate using the configuration provided. The SQL scripts (found in directories such as sql-scripts and in resource folders) indicate the data structure and set up for the student tracker.

##### Relationships and Interactions
- The Hibernate framework then interacts with the Domain/Entity objects, mapping them to database tables according to each mapping strategy.
- A directional flow from the Persistence Layer (Hibernate SessionFactory, Sessions, and transactions) to the Database, showing that operations like create, update, or query happen on the database.
- Dependency lines between the configuration and the SQL script resources, indicating that database schema definitions are incorporated through these scripts.

##### Architectural Patterns and Design Principles
- Modular Design: Each demo module is encapsulated, with its own pom.xml and resource folder. This design allows independent demonstration of different Hibernate mapping techniques.
- Separation of Concerns: Clear segregation between the application logic (the main demo classes), the Hibernate configuration and ORM framework (the persistence logic), and the database layer.
- Reusability: Although each module demonstrates a specific case (collections, inheritance, component mapping), they all follow a similar structure that isolates the configuration from domain logic.
- Configuration over Convention: The hibernate.cfg.xml files and explicit SQL scripts emphasize careful configuration management.

##### Relevant Technologies, Frameworks, and Libraries
- Java – The language used for implementing the demo applications.
- Maven – Each module contains a pom.xml that manages dependencies and build lifecycle.
- Hibernate ORM – The central framework used to map Java classes to database tables.
- SQL – Utilized for schema creation and testing via SQL scripts.
- (Optionally) Log frameworks or other utilities may exist but are not explicitly visible; focus primarily on the Hibernate and domain mapping aspects.

##### Final Assembly
- Next, have an intermediate layer for the Hibernate configuration/persistence framework, indicating that all modules funnel into this common layer.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Demo Modules Cluster
    subgraph "Demo Modules"
        subgraph "Map Collections Demos"
            A1["CreateStudentImagesSetDemo"]:::demo
            A2["CreateStudentImagesListDemo"]:::demo
            A3["CreateStudentImagesMapDemo"]:::demo
            A4["CreateStudentImagesSortedSetDemo"]:::demo
            A5["GetStudentImagesSortedSetDemo"]:::demo
            A6["CreateStudentImagesSortedMapDemo"]:::demo
            A7["GetStudentImagesSortedMapDemo"]:::demo
        end
        subgraph "Inheritance Demos"
            B1["CreateUserStudentInstructorDemo (Single Table)"]:::demo
            B2["CreateUserStudentInstructorDemo (Table Per Class)"]:::demo
            B3["CreateUserStudentInstructorDemo (Joined)"]:::demo
            B4["CreateUserStudentInstructorDemo (Mapped Superclass)"]:::demo
        end
        subgraph "Other Demos"
            C1["CreateStudentAddressDemo"]:::demo
            C2["CreateUserDemo"]:::demo
        end
    end

    %% Core Layers
    D["Hibernate SessionFactory & Configuration"]:::config
    E["Domain Entities (Student,Instructor,etc.)"]:::domain
    F["SQL Scripts (Schema Setup)"]:::persistence
    G(["Database"]):::database

    %% Connections from Demo Modules to Configuration
    A1 -->|"init_config"| D
    B1 -->|"init_config"| D
    C1 -->|"init_config"| D

    %% Configuration Layer interactions
    D -->|"reads_cfg"| F
    D -->|"maps_entities"| E

    %% Domain to Database operations
    E -->|"CRUD_ops"| G

    %% SQL Scripts to Database dependency
    F -->|"applies_schema"| G

    %% Click Events for Demo Modules - Map Collections
    click A1 "https://github.com/darbyluv2code/hibernate-advanced-development-techniques/blob/main/solution-code-hibernate-hb-01-map-collections-set/src/main/java/com/luv2code/hibernate/demo/CreateStudentImagesSetDemo.java"
    click A2 "https://github.com/darbyluv2code/hibernate-advanced-development-techniques/blob/main/solution-code-hibernate-hb-02-map-collections-list/src/main/java/com/luv2code/hibernate/demo/CreateStudentImagesListDemo.java"
    click A3 "https://github.com/darbyluv2code/hibernate-advanced-development-techniques/blob/main/solution-code-hibernate-hb-03-map-collections-map/src/main/java/com/luv2code/hibernate/demo/CreateStudentImagesMapDemo.java"
    click A4 "https://github.com/darbyluv2code/hibernate-advanced-development-techniques/blob/main/solution-code-hibernate-hb-04-map-collections-sortedset/src/main/java/com/luv2code/hibernate/demo/CreateStudentImagesSortedSetDemo.java"
    click A5 "https://github.com/darbyluv2code/hibernate-advanced-development-techniques/blob/main/solution-code-hibernate-hb-04-map-collections-sortedset/src/main/java/com/luv2code/hibernate/demo/GetStudentImagesDemo.java"
    click A6 "https://github.com/darbyluv2code/hibernate-advanced-development-techniques/blob/main/solution-code-hibernate-hb-05-map-collections-sortedmap/src/main/java/com/luv2code/hibernate/demo/CreateStudentImagesSortedMapDemo.java"
    click A7 "https://github.com/darbyluv2code/hibernate-advanced-development-techniques/blob/main/solution-code-hibernate-hb-05-map-collections-sortedmap/src/main/java/com/luv2code/hibernate/demo/GetStudentImagesDemo.java"

    %% Click Events for Demo Modules - Inheritance Demos
    click B1 "https://github.com/darbyluv2code/hibernate-advanced-development-techniques/blob/main/solution-code-hibernate-hb-inheritance-01-singletable/src/main/java/com/luv2code/hibernate/demo/CreateUserStudentInstructorDemo.java"
    click B2 "https://github.com/darbyluv2code/hibernate-advanced-development-techniques/blob/main/solution-code-hibernate-hb-inheritance-02-tableperclass/src/main/java/com/luv2code/hibernate/demo/CreateUserStudentInstructorDemo.java"
    click B3 "https://github.com/darbyluv2code/hibernate-advanced-development-techniques/blob/main/solution-code-hibernate-hb-inheritance-03-joined/src/main/java/com/luv2code/hibernate/demo/CreateUserStudentInstructorDemo.java"
    click B4 "https://github.com/darbyluv2code/hibernate-advanced-development-techniques/blob/main/solution-code-hibernate-hb-inheritance-04-mappedsuperclass/src/main/java/com/luv2code/hibernate/demo/CreateUserStudentInstructorDemo.java"

    %% Click Events for Demo Modules - Other Demos
    click C1 "https://github.com/darbyluv2code/hibernate-advanced-development-techniques/blob/main/solution-code-hibernate-hb-map-components/src/main/java/com/luv2code/hibernate/demo/CreateStudentAddressDemo.java"
    click C2 "https://github.com/darbyluv2code/hibernate-advanced-development-techniques/blob/main/solution-code-hibernate-hb-map-enum/src/main/java/com/luv2code/hibernate/demo/CreateUserDemo.java"

    %% Click Event for Configuration Layer
    click D "https://github.com/darbyluv2code/hibernate-advanced-development-techniques/blob/main/solution-code-hibernate-hb-01-map-collections-set/src/main/resources/hibernate.cfg.xml"

    %% Click Event for Domain/Entity Layer
    click E "https://github.com/darbyluv2code/hibernate-advanced-development-techniques/blob/main/solution-code-hibernate-hb-01-map-collections-set/src/main/java/com/luv2code/hibernate/demo/entity/Student.java"

    %% Click Events for Persistence Layer and Database
    click F "https://github.com/darbyluv2code/hibernate-advanced-development-techniques/blob/main/advanced-hibernate-starter-code/sql-scripts/hb_student_tracker_student.sql"
    click G "https://github.com/darbyluv2code/hibernate-advanced-development-techniques/blob/main/advanced-hibernate-starter-code/sql-scripts/hb_student_tracker_student.sql"

    %% Styles
    classDef demo fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef config fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef domain fill:#F9E79F,stroke:#D4AC0D,stroke-width:2px;
    classDef persistence fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;
    classDef database fill:#D5DBDB,stroke:#1C2833,stroke-width:2px;
```
