Files
..

formula-filter

Companion module for the ankurm.com article @Formula, @Filter and @SQLRestriction in Hibernate 7: Computed and Filtered Data. Every SQL statement, result and error message in the article comes from a test here; each test writes what it observed to output/ and asserts the same facts. Plain Hibernate on an in-memory H2: no Spring, no Docker, no database server.

Versions

Component Version Notes
Hibernate ORM 7.4.17.Final newest 7.x GA in maven-metadata.xml on 2026-11-26
Jakarta Persistence 3.2.0
H2 2.4.240 in memory
JUnit / AssertJ 6.0.3 / 3.27.7
Java 25 (Temurin 25.0.5.1 LTS)

Run

./scripts/run-all.sh      # mvn clean test, then the compile-failure demo; regenerates everything in output/

Tests and what they write

Test Output Question it answers
T01_FormulaTest.formula output/01-formula.txt What SQL does @Formula add, where is it repeated, when does the value go stale, is it really read-only?
T01_FormulaTest.unqualifiedColumnInsideSubselect output/02-formula-unqualified.txt Why does a column inside a formula's sub-select fail with the outer table's alias?
T03_SqlRestrictionTest output/03-sql-restriction.txt Where does @SQLRestriction reach: find-by-id, collections, join fetch, bulk DML, native SQL, dangling references
T04_FilterTest.filter output/04-filter.txt Where does @Filter reach, and which places does it silently skip (find-by-id, collections, already-loaded collections)
T04_FilterTest.applyToLoadByKey output/05-apply-to-load-by-key.txt What does applyToLoadByKey = true change
T06_AutoEnabledTest output/06-auto-enabled.txt autoEnabled + a parameter resolver as a tenant filter, and the find-by-id gap
scripts/compile-broken.sh output/07-where-removed.txt The compiler error for @Where, which Hibernate 7 removed

The mappings live in src/main/java/com/ankurm/formulafilter/: Person and Invoice (@Formula), Task / Department / Ticket (@SQLRestriction, @Filter), Document and Memo (autoEnabled). src/broken/ is deliberately outside the Maven build.