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,93 @@
|
||||
# @ElementCollection of record Tag(name, colour): Set vs List (bag) vs List with @OrderColumn
|
||||
# Hibernate ORM 7.4.17.Final, H2 2.4.240, JDK 25
|
||||
|
||||
== Columns of table article_tagset
|
||||
ARTICLE_ID | BIGINT | null | 64 | 0 | NO
|
||||
COLOUR | CHARACTER VARYING | 255 | null | null | YES
|
||||
NAME | CHARACTER VARYING | 255 | null | null | YES
|
||||
|
||||
== Columns of table article_tagbag
|
||||
ARTICLE_ID | BIGINT | null | 64 | 0 | NO
|
||||
COLOUR | CHARACTER VARYING | 255 | null | null | YES
|
||||
NAME | CHARACTER VARYING | 255 | null | null | YES
|
||||
|
||||
== Columns of table article_tagordered
|
||||
TAGORDERED_ORDER | INTEGER | null | 32 | 0 | NO
|
||||
ARTICLE_ID | BIGINT | null | 64 | 0 | NO
|
||||
COLOUR | CHARACTER VARYING | 255 | null | null | YES
|
||||
NAME | CHARACTER VARYING | 255 | null | null | YES
|
||||
|
||||
== Columns of table article_strictset
|
||||
ARTICLE_ID | BIGINT | null | 64 | 0 | NO
|
||||
COLOUR | CHARACTER VARYING | 255 | null | null | NO
|
||||
NAME | CHARACTER VARYING | 255 | null | null | NO
|
||||
|
||||
primary key / unique constraints (table, columns):
|
||||
ARTICLE_STRICTSET | PRIMARY KEY | ARTICLE_ID,COLOUR,NAME
|
||||
ARTICLE_TAGORDERED | PRIMARY KEY | TAGORDERED_ORDER,ARTICLE_ID
|
||||
|
||||
== Removing one of three elements
|
||||
-- Set: remove Tag(jpa, blue)
|
||||
sql> select a1_0.id from Article a1_0 where a1_0.id=?
|
||||
sql> select ts1_0.Article_id,ts1_0.name,ts1_0.colour from Article_tagSet ts1_0 where ts1_0.Article_id=?
|
||||
sql> delete from Article_tagSet where Article_id=?
|
||||
sql> insert into Article_tagSet (Article_id,name,colour) values (?,?,?)
|
||||
sql> insert into Article_tagSet (Article_id,name,colour) values (?,?,?)
|
||||
=> true
|
||||
-- Set with NOT NULL components: remove NnTag(jpa, blue)
|
||||
sql> select a1_0.id from Article a1_0 where a1_0.id=?
|
||||
sql> select ss1_0.Article_id,ss1_0.name,ss1_0.colour from Article_strictSet ss1_0 where ss1_0.Article_id=?
|
||||
sql> delete from Article_strictSet where Article_id=? and name=? and colour=?
|
||||
=> true
|
||||
-- List (bag): remove Tag(jpa, blue)
|
||||
sql> select a1_0.id from Article a1_0 where a1_0.id=?
|
||||
sql> select tb1_0.Article_id,tb1_0.name,tb1_0.colour from Article_tagBag tb1_0 where tb1_0.Article_id=?
|
||||
sql> delete from Article_tagBag where Article_id=?
|
||||
sql> insert into Article_tagBag (Article_id,name,colour) values (?,?,?)
|
||||
sql> insert into Article_tagBag (Article_id,name,colour) values (?,?,?)
|
||||
=> true
|
||||
inserts after the delete: 2
|
||||
-- List with @OrderColumn: remove Tag(jpa, blue)
|
||||
sql> select a1_0.id from Article a1_0 where a1_0.id=?
|
||||
sql> select to1_0.Article_id,to1_0.tagOrdered_ORDER,to1_0.name,to1_0.colour from Article_tagOrdered to1_0 where to1_0.Article_id=?
|
||||
sql> delete from Article_tagOrdered where Article_id=? and tagOrdered_ORDER=?
|
||||
sql> update Article_tagOrdered set name=?,colour=? where Article_id=? and tagOrdered_ORDER=?
|
||||
=> true
|
||||
|
||||
== Adding one element
|
||||
-- Set: add Tag(hql, grey)
|
||||
sql> select a1_0.id from Article a1_0 where a1_0.id=?
|
||||
sql> select ts1_0.Article_id,ts1_0.name,ts1_0.colour from Article_tagSet ts1_0 where ts1_0.Article_id=?
|
||||
sql> delete from Article_tagSet where Article_id=?
|
||||
sql> insert into Article_tagSet (Article_id,name,colour) values (?,?,?)
|
||||
sql> insert into Article_tagSet (Article_id,name,colour) values (?,?,?)
|
||||
sql> insert into Article_tagSet (Article_id,name,colour) values (?,?,?)
|
||||
=> true
|
||||
-- List (bag): add Tag(hql, grey)
|
||||
sql> select a1_0.id from Article a1_0 where a1_0.id=?
|
||||
sql> select tb1_0.Article_id,tb1_0.name,tb1_0.colour from Article_tagBag tb1_0 where tb1_0.Article_id=?
|
||||
sql> delete from Article_tagBag where Article_id=?
|
||||
sql> insert into Article_tagBag (Article_id,name,colour) values (?,?,?)
|
||||
sql> insert into Article_tagBag (Article_id,name,colour) values (?,?,?)
|
||||
sql> insert into Article_tagBag (Article_id,name,colour) values (?,?,?)
|
||||
=> true
|
||||
-- Set with NOT NULL components: add NnTag(hql, grey)
|
||||
sql> select a1_0.id from Article a1_0 where a1_0.id=?
|
||||
sql> select ss1_0.Article_id,ss1_0.name,ss1_0.colour from Article_strictSet ss1_0 where ss1_0.Article_id=?
|
||||
sql> insert into Article_strictSet (Article_id,name,colour) values (?,?,?)
|
||||
=> true
|
||||
-- List with @OrderColumn: add Tag(hql, grey)
|
||||
sql> select a1_0.id from Article a1_0 where a1_0.id=?
|
||||
sql> select to1_0.Article_id,to1_0.tagOrdered_ORDER,to1_0.name,to1_0.colour from Article_tagOrdered to1_0 where to1_0.Article_id=?
|
||||
sql> insert into Article_tagOrdered (Article_id,tagOrdered_ORDER,name,colour) values (?,?,?,?)
|
||||
=> true
|
||||
|
||||
== Replacing the whole collection with an equal one
|
||||
-- Set: replace with new LinkedHashSet of equal records
|
||||
sql> select a1_0.id from Article a1_0 where a1_0.id=?
|
||||
sql> select ts1_0.Article_id,ts1_0.name,ts1_0.colour from Article_tagSet ts1_0 where ts1_0.Article_id=?
|
||||
sql> delete from Article_tagSet where Article_id=?
|
||||
sql> insert into Article_tagSet (Article_id,name,colour) values (?,?,?)
|
||||
sql> insert into Article_tagSet (Article_id,name,colour) values (?,?,?)
|
||||
sql> insert into Article_tagSet (Article_id,name,colour) values (?,?,?)
|
||||
=> 3
|
||||
Reference in New Issue
Block a user