Files

2.7 KiB

embeddables

Companion module for the ankurm.com article Records and Value Objects in Hibernate 7: @Embeddable Records Done Right. 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 (8.0.0.CR2 is listed after it, but CR2 is not GA)
Jakarta Persistence 3.2.0 newest GA in maven-metadata.xml (4.0.0-M8 is a milestone); also what hibernate-core:7.4.17.Final's POM depends on
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 jar search; regenerates everything in output/

Tests and what they write

Test Output Question it answers
T01_BasicTest.basic output/01-basic.txt What does @Embeddable record Money map to, how does it round-trip, how is an update detected?
T01_BasicTest.sameRecordTwice output/02-two-uses.txt Same record twice in one entity (@AttributeOverride), nested record (Geo inside Address)
T02_NullTest.nulls output/03-nulls.txt All-null columns, partly-null columns, is null queries, a compact constructor that rejects nulls, the create_empty_composites setting
T02_NullTest.primitivesAndNotNull output/04-primitives.txt A record with int components as an optional embedded attribute
T03_CollectionTest.collections output/05-collections.txt @ElementCollection of records: Set vs List vs @OrderColumn vs Set with NOT NULL components, SQL for add and remove
T03_CollectionTest.nullsInsideElements output/06-collection-nulls.txt Null components and all-null elements in a collection
T04_EqualityTest output/07-equality.txt Record equals vs database equality, embeddables in HQL, record as @EmbeddedId
T05_ValueObjectTest output/08-value-object.txt record Email(String value): normalisation, queries, invalid data already in the table
T06_FailuresTest output/09-failures.txt Duplicate columns, a component named value, a record without @Embeddable, a record as @Entity
scripts/search-setting.sh output/10-setting-search.txt Does create_empty_composites occur anywhere in the Hibernate 7.4.17 jar?

Entities and embeddables are in src/main/java/com/ankurm/embeddables; Db and Transcript in src/test capture every SQL statement Hibernate prepares.