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,33 @@
|
||||
# Things that go wrong with record embeddables
|
||||
# Hibernate ORM 7.4.17.Final, H2 2.4.240, JDK 25
|
||||
|
||||
== Same record embedded twice without @AttributeOverride
|
||||
org.hibernate.MappingException: Column 'street' is duplicated in mapping for entity 'com.ankurm.embeddables.BadCustomer' (use '@Column(insertable=false, updatable=false)' when mapping multiple properties to the same column)
|
||||
|
||||
== A component called value (record Handle(String value))
|
||||
session factory started; columns of table account: []
|
||||
-- persist Account(1, Handle(x))
|
||||
sql> insert into Account (value,id) values (?,?)
|
||||
=> SQLGrammarException: Could not prepare statement [Table "ACCOUNT" not found (this database is empty); SQL statement: [root cause: JdbcSQLSyntaxErrorException: Table "ACCOUNT" not found (this database is empty); SQL statement:]
|
||||
|
||||
== The same DDL typed by hand into H2 (create table t(value varchar(5)))
|
||||
Syntax error in SQL statement "create table t([*]value varchar(5))"; expected "identifier"; SQL statement:
|
||||
|
||||
== A record that is not annotated @Embeddable, used with @Embedded (Holder.money is a PlainMoney)
|
||||
session factory started; columns of table holder: [AMOUNT | NUMERIC | null | 38 | 2 | YES, ID | BIGINT | null | 64 | 0 | NO, CURRENCY | CHARACTER VARYING | 255 | null | null | YES]
|
||||
-- persist Holder(1, PlainMoney(5, INR)) and load it
|
||||
sql> insert into Holder (amount,currency,id) values (?,?,?)
|
||||
sql> select h1_0.id,h1_0.amount,h1_0.currency from Holder h1_0 where h1_0.id=?
|
||||
=> PlainMoney[amount=5.00, currency=INR]
|
||||
|
||||
== A record as @Entity
|
||||
session factory started; columns of table recordentity: [ID | BIGINT | null | 64 | 0 | NO, NAME | CHARACTER VARYING | 255 | null | null | YES]
|
||||
-- persist RecordEntity(1, first)
|
||||
sql> insert into RecordEntity (name,id) values (?,?)
|
||||
=> persisted
|
||||
-- find it back
|
||||
sql> select re1_0.id,re1_0.name from RecordEntity re1_0 where re1_0.id=?
|
||||
=> InstantiationException: No default constructor for entity 'com.ankurm.embeddables.RecordEntity'
|
||||
-- merge(new RecordEntity(1, second)) and find again
|
||||
sql> select re1_0.id,re1_0.name from RecordEntity re1_0 where re1_0.id=?
|
||||
=> InstantiationException: No default constructor for entity 'com.ankurm.embeddables.RecordEntity'
|
||||
Reference in New Issue
Block a user