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.
- ☕ Java 17
- 🌱 Spring Boot 4.1.x
- 🗃️ Spring Data JPA (Hibernate)
- 💾 H2 (in-memory database)
- 🐘 Gradle (Groovy DSL)
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
- 🏷️
@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 anUPDATEonly once the persistence context is flushed, without ever callingsave()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
- JDK 17 or later
- No local database needed — H2 runs in-memory
./gradlew bootRunWatch the console — you'll see Hibernate-generated SQL logged in real time as the app runs through: save → find → mutate → flush.
./gradlew testapplication.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: TRACEINFO) for anything beyond local experimentation — this level of logging is not meant for production.
- 📝 Blog post:Programming Paradigm and where it came from
Personal learning project — no license restrictions, feel free to reuse or adapt. 🙌