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
+36
View File
@@ -0,0 +1,36 @@
# @Embeddable record Money(amount, currency) inside Product
# Hibernate ORM 7.4.17.Final, H2 2.4.240, JDK 25
== Columns of table product
AMOUNT | NUMERIC | null | 12 | 2 | YES
CURRENCY | CHARACTER VARYING | 3 | null | null | YES
ID | BIGINT | null | 64 | 0 | NO
NAME | CHARACTER VARYING | 255 | null | null | YES
== Insert and load
-- persist Product(1, Keyboard, Money(10.5, INR))
sql> insert into Product (name,amount,currency,id) values (?,?,?,?)
=> persisted
in database: [10.50 | INR | 1 | Keyboard]
-- load Product 1 in a new session
sql> select p1_0.id,p1_0.name,p1_0.amount,p1_0.currency from Product p1_0 where p1_0.id=?
=> Money[amount=10.50, currency=INR]
in-memory Money(10.5, INR).equals(Money loaded back from NUMERIC(12,2)) = false
== Updating: replace the whole record
-- replace price with Money(12.00, INR)
sql> select p1_0.id,p1_0.name,p1_0.amount,p1_0.currency from Product p1_0 where p1_0.id=?
sql> update Product set name=?,amount=?,currency=? where id=?
=> replaced
-- replace price with an equal-valued Money(12.0, INR) (scale 1 vs 2)
sql> select p1_0.id,p1_0.name,p1_0.amount,p1_0.currency from Product p1_0 where p1_0.id=?
=> replaced
record equals says: false
update issued: false
-- replace price with a really different Money(13.00, INR)
sql> select p1_0.id,p1_0.name,p1_0.amount,p1_0.currency from Product p1_0 where p1_0.id=?
sql> update Product set name=?,amount=?,currency=? where id=?
=> replaced
-- replace price with an identical new instance Money(13.00, INR)
sql> select p1_0.id,p1_0.name,p1_0.amount,p1_0.currency from Product p1_0 where p1_0.id=?
=> replaced