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:
@@ -0,0 +1,32 @@
|
||||
# equals/hashCode of records, and comparing embeddables in HQL
|
||||
# Hibernate ORM 7.4.17.Final, H2 2.4.240, JDK 25
|
||||
Money(10.0, INR).equals(Money(10.00, INR)) = false
|
||||
Money(10.00, INR).equals(Money(10.00, INR)) = true
|
||||
hashCodes of 10.0 vs 10.00 Money equal = false
|
||||
new HashSet(List.of(10.0, 10.00)).size() = 2
|
||||
|
||||
== Comparing an embeddable in HQL
|
||||
-- from Product p where p.price = :m (m = Money(10.0, INR))
|
||||
sql> select p1_0.id,p1_0.name,p1_0.amount,p1_0.currency from Product p1_0 where (p1_0.amount,p1_0.currency)=(?,?)
|
||||
=> [1]
|
||||
-- from Product p where p.price in (:a, :b)
|
||||
sql> select p1_0.id,p1_0.name,p1_0.amount,p1_0.currency from Product p1_0 where (p1_0.amount,p1_0.currency) in ((?,?),(?,?))
|
||||
=> [1, 2]
|
||||
-- select p.price from Product p order by p.id (an embeddable as a result)
|
||||
sql> select p1_0.amount,p1_0.currency from Product p1_0 order by p1_0.id
|
||||
=> [Money[amount=10.00, currency=INR], Money[amount=20.00, currency=INR], null]
|
||||
-- select p.price.amount from Product p order by p.price.amount desc
|
||||
sql> select p1_0.amount from Product p1_0 order by p1_0.amount desc
|
||||
=> [20.00, 10.00, null]
|
||||
-- select new Money(p.price.amount, 'USD') from Product p where p.id = 1 (constructor expression)
|
||||
sql> select p1_0.amount,'USD' from Product p1_0 where p1_0.id=1
|
||||
=> [Money[amount=10.00, currency=USD]]
|
||||
|
||||
== A record as @EmbeddedId
|
||||
Columns: [LINE | INTEGER | null | 32 | 0 | NO, ORDERID | BIGINT | null | 64 | 0 | NO, SKU | CHARACTER VARYING | 255 | null | null | YES]
|
||||
-- find(OrderLine.class, new OrderLineId(7, 1))
|
||||
sql> select ol1_0.orderId,ol1_0.line,ol1_0.sku from OrderLine ol1_0 where (ol1_0.orderId,ol1_0.line) in ((?,?))
|
||||
=> SKU-A
|
||||
-- same session twice: find with two equal-but-distinct keys, same instance?
|
||||
sql> select ol1_0.orderId,ol1_0.line,ol1_0.sku from OrderLine ol1_0 where (ol1_0.orderId,ol1_0.line) in ((?,?))
|
||||
=> true
|
||||
Reference in New Issue
Block a user