Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚗 Spring Boot OOP & JPA Demo

A small hands-on project built to demonstrate how object-oriented programming concepts (classes, inheritance, polymorphism) translate into a real Spring Boot + JPA/Hibernate application — and to actually watch Hibernate work through console logs.

This project accompanies a blog series on programming paradigms and OOP. It shows how a simple Car entity gets persisted, queried, and updated, and how Hibernate's dirty checking mechanism triggers an UPDATE without ever writing raw SQL.

🛠️ Tech Stack

  • ☕ Java 17
  • 🌱 Spring Boot 4.1.x
  • 🗃️ Spring Data JPA (Hibernate)
  • 💾 H2 (in-memory database)
  • 🐘 Gradle (Groovy DSL)

📁 Project Structure

demo/
├── build.gradle
├── settings.gradle
└── src/
    ├── main/
    │   ├── java/com/example/demo/
    │   │   ├── DemoApplication.java       # Entry point + CommandLineRunner demo logic
    │   │   ├── entity/
    │   │   │   └── Car.java               # JPA entity
    │   │   └── repository/
    │   │       └── CarRepository.java     # Spring Data JPA repository
    │   └── resources/
    │       └── application.yml            # DB + logging configuration
    └── test/
        └── java/com/example/demo/
            └── DemoApplicationTests.java  # @DataJpaTest slice tests

✨ What This Demonstrates

  • 🏷️ @Entity / @Id / @GeneratedValue — how a plain Java class becomes a table-mapped object (ORM)
  • 🔌 Repository interfaces — how Spring Data JPA generates a runtime proxy implementation with zero hand-written SQL
  • 🕵️ Dirty checking — how modifying a managed entity's field (car.accelerate(20)) produces an UPDATE only once the persistence context is flushed, without ever calling save() again
  • Dynamic dispatch in practice — how DI containers (Spring's ApplicationContext) decide at runtime which implementation actually runs, conceptually mirroring vtable-based dispatch at the JVM level

🚀 Getting Started

✅ Prerequisites

  • JDK 17 or later
  • No local database needed — H2 runs in-memory

▶️ Run the app

./gradlew bootRun

Watch the console — you'll see Hibernate-generated SQL logged in real time as the app runs through: save → find → mutate → flush.

🧪 Run the tests

./gradlew test

⚙️ Configuration Notes

application.yml enables verbose Hibernate logging so the underlying SQL and dirty-checking behavior is visible:

logging:
  level:
    org.hibernate.SQL: DEBUG
    org.hibernate.orm.jdbc.bind: TRACE

⚠️ Turn these off (or drop to INFO) for anything beyond local experimentation — this level of logging is not meant for production.

📚 Related Reading

📄 License

Personal learning project — no license restrictions, feel free to reuse or adapt. 🙌

About

This is a small Spring Boot project you can demonstrate how Spring Boot Hibernate works on your computer.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages