|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is a demonstration project for Hibernate Extended Bytecode Enhancement, accompanying the Medium article "Hibernate Extended Bytecode Enhancement". The project shows how Hibernate's bytecode enhancement can automatically detect field changes even when they occur outside of setter methods. |
| 8 | + |
| 9 | +## Build System & Commands |
| 10 | + |
| 11 | +This is a Maven-based Java project using Java 14. |
| 12 | + |
| 13 | +### Essential Commands |
| 14 | +- **Build**: `mvn clean compile` |
| 15 | +- **Run tests**: `mvn test` |
| 16 | +- **Run single test**: `mvn test -Dtest=ExtendedEnhancementTest` |
| 17 | +- **Clean**: `mvn clean` |
| 18 | + |
| 19 | +### Dependencies |
| 20 | +- Hibernate Core 5.6.15.Final |
| 21 | +- H2 Database 2.3.232 (for testing) |
| 22 | +- JUnit Jupiter 5.13.4 (for testing) |
| 23 | + |
| 24 | +## Architecture |
| 25 | + |
| 26 | +### Core Components |
| 27 | + |
| 28 | +The project demonstrates Hibernate's extended enhancement feature through: |
| 29 | + |
| 30 | +1. **Cat.java** (`src/main/java/com/forketyfork/hibernate/Cat.java`): JPA entity with: |
| 31 | + - Standard getter/setter methods |
| 32 | + - `myCustomMethodToChangeData()` that directly modifies the `name` field |
| 33 | + |
| 34 | +2. **SneakyCatService.java** (`src/main/java/com/forketyfork/hibernate/SneakyCatService.java`): Service that directly accesses entity fields bypassing setters via `cat.name = "Buddy"` |
| 35 | + |
| 36 | +3. **ExtendedEnhancementTest.java** (`src/test/java/com/forketyfork/hibernate/ExtendedEnhancementTest.java`): Integration test demonstrating that Hibernate can detect changes made through: |
| 37 | + - Custom methods that modify fields directly |
| 38 | + - External services accessing package-private fields |
| 39 | + |
| 40 | +### Hibernate Enhancement Configuration |
| 41 | + |
| 42 | +The Maven build uses `hibernate-enhance-maven-plugin` with: |
| 43 | +- `enableDirtyTracking=true`: Tracks which fields have been modified |
| 44 | +- `enableExtendedEnhancement=true`: Detects field changes even when setters aren't used |
| 45 | +- Version 6.6.22.Final (newer than core Hibernate for enhanced features) |
| 46 | + |
| 47 | +### Test Database Setup |
| 48 | + |
| 49 | +Tests use H2 in-memory database with Hibernate configured for: |
| 50 | +- Auto-create schema (`hibernate.hbm2ddl.auto=create-drop`) |
| 51 | +- SQL logging enabled (`hibernate.show_sql=true`) |
| 52 | + |
| 53 | +The test verifies that field modifications are properly persisted regardless of how they're made, demonstrating the power of extended bytecode enhancement. |
0 commit comments