Add embeddables module: @Embeddable records in Hibernate 7.4.17.Final (columns and round trip, null handling, collections of embeddables and their SQL, record equality vs database equality, @EmbeddedId records, DDD Email value object, failure modes; H2)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b3obqqePfZ9m2Jk5Ub
This commit is contained in:
Claude
2026-11-26 18:14:43 +05:30
parent ec6eda8650
commit 4c795e8b50
45 changed files with 1453 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
# record Email(String value) as a DDD value object
# Hibernate ORM 7.4.17.Final, H2 2.4.240, JDK 25
== Columns of table member
ID | BIGINT | null | 64 | 0 | NO
EMAIL | CHARACTER VARYING | 255 | null | null | YES
stored value: [1 | [email protected]]
== Queries
-- from Member m where m.email = :e (e = new Email("[email protected]"))
sql> select m1_0.id,m1_0.email from Member m1_0 where m1_0.email=?
=> 1
-- from Member m where m.email.value like '%@example.com'
sql> select m1_0.id,m1_0.email from Member m1_0 where m1_0.email like '%@example.com' escape ''
=> 1
-- select m.email from Member m
sql> select m1_0.email from Member m1_0
=> [Email[[email protected]]]
== Bad data already in the table
-- find Member 2
sql> select m1_0.id,m1_0.email from Member m1_0 where m1_0.id=?
=> InstantiationException: Could not instantiate entity 'com.ankurm.embeddables.Email' due to: null [root cause: IllegalArgumentException: not an email address: not-an-address]
-- from Member (loads both rows)
sql> select m1_0.id,m1_0.email from Member m1_0 order by m1_0.id
=> InstantiationException: Could not instantiate entity 'com.ankurm.embeddables.Email' due to: null [root cause: IllegalArgumentException: not an email address: not-an-address]
-- select m.id from Member m (does not touch the Email)
sql> select m1_0.id from Member m1_0 order by m1_0.id
=> [1, 2]