Kohei Nozaki's blog 

Just try to use ElementCollection with List


Posted on Tuesday Feb 18, 2014 at 02:45PM in Technology


As I tried in Just try to use ElementCollection with Set, this is for Lists.

Environment

  • WildFly 8.0.0.Final
  • Hibernate 4.3.1
  • PostgreSQL 9.2.4
  • postgresql-9.3-1100.jdbc41.jar

Example project

Whole project resources are available in GitHub.

Ordering of elements

  • According to the spec, ordering of elements will not be kept by JPA as default.
  • It can be achieved easily with @OrderBy or @OrderColumn.
    • Now It works for ElementCollection with basic type at recent versions of Hibernate[1].

List<Basic> with @OrderBy

Schema

jpatest=# \d listbasicorderby
Table "public.listbasicorderby"
 Column |  Type  | Modifiers 
--------+--------+-----------
 id     | bigint | not null
Indexes:
    "listbasicorderby_pkey" PRIMARY KEY, btree (id)
Referenced by:
    TABLE "listbasicorderby_list" CONSTRAINT "fk_5fs67i9n98xsp58x8vp4myxq8" FOREIGN KEY (listbasicorderby_id) REFERENCES listbasicorderby(id)

jpatest=# \d listbasicorderby_list 
           Table "public.listbasicorderby_list"
       Column        |          Type          | Modifiers 
---------------------+------------------------+-----------
 listbasicorderby_id | bigint                 | not null
 list                | character varying(255) | 
Foreign-key constraints:
    "fk_5fs67i9n98xsp58x8vp4myxq8" FOREIGN KEY (listbasicorderby_id) REFERENCES listbasicorderby(id)

jpatest=# 

Entry data

log

15:42:35,481 DEBUG [org.hibernate.SQL] (default task-6) insert into ListBasicOrderBy (id) values (?)
15:42:35,481 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [1] as [BIGINT] - [1]
15:42:35,482 DEBUG [org.hibernate.SQL] (default task-6) insert into ListBasicOrderBy_list (ListBasicOrderBy_id, list) values (?, ?)
15:42:35,482 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [1] as [BIGINT] - [1]
15:42:35,482 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [2] as [VARCHAR] - [hoge]
15:42:35,484 DEBUG [org.hibernate.SQL] (default task-6) insert into ListBasicOrderBy_list (ListBasicOrderBy_id, list) values (?, ?)
15:42:35,484 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [1] as [BIGINT] - [1]
15:42:35,484 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [2] as [VARCHAR] - [hoge]
15:42:35,484 DEBUG [org.hibernate.SQL] (default task-6) insert into ListBasicOrderBy_list (ListBasicOrderBy_id, list) values (?, ?)
15:42:35,484 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [1] as [BIGINT] - [1]
15:42:35,484 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [2] as [VARCHAR] - [hige]

table

jpatest=# select * from listbasicorderby;
 id 
----
  1
(1 row)

jpatest=# select * from listbasicorderby_list order by list;
 listbasicorderby_id | list 
---------------------+------
                   1 | hige
                   1 | hoge
                   1 | hoge
(3 rows)

Find

15:58:19,719 DEBUG [org.hibernate.SQL] (default task-15) select listbasico0_.id as id1_0_0_ from ListBasicOrderBy listbasico0_ where listbasico0_.id=?
15:58:19,720 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-15) binding parameter [1] as [BIGINT] - [1]
15:58:19,721 DEBUG [org.hibernate.SQL] (default task-15) select list0_.ListBasicOrderBy_id as ListBasi1_0_0_, list0_.list as list2_1_0_ from ListBasicOrderBy_list list0_ where list0_.ListBasicOrderBy_id=? order by list0_.list asc
15:58:19,721 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-15) binding parameter [1] as [BIGINT] - [1]
15:58:19,721 FINE  [org.nailedtothex.jpatest.list.ListBasicTestDataManipulator] (default task-15) find(): [hige, hoge, hoge]

Add

log

16:05:46,474 DEBUG [org.hibernate.SQL] (default task-14) select listbasico0_.id as id1_0_0_ from ListBasicOrderBy listbasico0_ where listbasico0_.id=?
16:05:46,474 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [1] as [BIGINT] - [1]
16:05:46,475 DEBUG [org.hibernate.SQL] (default task-14) select list0_.ListBasicOrderBy_id as ListBasi1_0_0_, list0_.list as list2_1_0_ from ListBasicOrderBy_list list0_ where list0_.ListBasicOrderBy_id=? order by list0_.list asc
16:05:46,476 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [1] as [BIGINT] - [1]
16:05:46,480 DEBUG [org.hibernate.SQL] (default task-14) delete from ListBasicOrderBy_list where ListBasicOrderBy_id=?
16:05:46,480 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [1] as [BIGINT] - [1]
16:05:46,481 DEBUG [org.hibernate.SQL] (default task-14) insert into ListBasicOrderBy_list (ListBasicOrderBy_id, list) values (?, ?)
16:05:46,481 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [1] as [BIGINT] - [1]
16:05:46,481 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [2] as [VARCHAR] - [hige]
16:05:46,481 DEBUG [org.hibernate.SQL] (default task-14) insert into ListBasicOrderBy_list (ListBasicOrderBy_id, list) values (?, ?)
16:05:46,482 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [1] as [BIGINT] - [1]
16:05:46,482 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [2] as [VARCHAR] - [hoge]
16:05:46,482 DEBUG [org.hibernate.SQL] (default task-14) insert into ListBasicOrderBy_list (ListBasicOrderBy_id, list) values (?, ?)
16:05:46,482 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [1] as [BIGINT] - [1]
16:05:46,482 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [2] as [VARCHAR] - [hoge]
16:05:46,483 DEBUG [org.hibernate.SQL] (default task-14) insert into ListBasicOrderBy_list (ListBasicOrderBy_id, list) values (?, ?)
16:05:46,483 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [1] as [BIGINT] - [1]
16:05:46,483 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [2] as [VARCHAR] - [hige]

table

jpatest=# select * from listbasicorderby_list order by list;
 listbasicorderby_id | list 
---------------------+------
                   1 | hige
                   1 | hige
                   1 | hoge
                   1 | hoge
(4 rows)

jpatest=# 
  • Surprisingly, Hibernate deletes all of elements, and insert them again.

Remove

log

16:14:09,474 DEBUG [org.hibernate.SQL] (default task-3) select listbasico0_.id as id1_0_0_ from ListBasicOrderBy listbasico0_ where listbasico0_.id=?
16:14:09,474 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-3) binding parameter [1] as [BIGINT] - [1]
16:14:09,475 DEBUG [org.hibernate.SQL] (default task-3) select list0_.ListBasicOrderBy_id as ListBasi1_0_0_, list0_.list as list2_1_0_ from ListBasicOrderBy_list list0_ where list0_.ListBasicOrderBy_id=? order by list0_.list asc
16:14:09,475 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-3) binding parameter [1] as [BIGINT] - [1]
16:14:09,480 DEBUG [org.hibernate.SQL] (default task-3) delete from ListBasicOrderBy_list where ListBasicOrderBy_id=?
16:14:09,480 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-3) binding parameter [1] as [BIGINT] - [1]
16:14:09,480 DEBUG [org.hibernate.SQL] (default task-3) insert into ListBasicOrderBy_list (ListBasicOrderBy_id, list) values (?, ?)
16:14:09,480 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-3) binding parameter [1] as [BIGINT] - [1]
16:14:09,480 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-3) binding parameter [2] as [VARCHAR] - [hige]
16:14:09,481 DEBUG [org.hibernate.SQL] (default task-3) insert into ListBasicOrderBy_list (ListBasicOrderBy_id, list) values (?, ?)
16:14:09,481 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-3) binding parameter [1] as [BIGINT] - [1]
16:14:09,481 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-3) binding parameter [2] as [VARCHAR] - [hoge]

table

jpatest=# select * from listbasicorderby_list order by list;
 listbasicorderby_id | list 
---------------------+------
                   1 | hige
                   1 | hoge
(2 rows)

jpatest=# 
  • Hibernate deletes all of elements again, same as preceding try.

List<Basic> with @OrderColumn

Schema

jpatest=# \d listbasicordercolumn
Table "public.listbasicordercolumn"
 Column |  Type  | Modifiers 
--------+--------+-----------
 id     | bigint | not null
Indexes:
    "listbasicordercolumn_pkey" PRIMARY KEY, btree (id)
Referenced by:
    TABLE "listbasicordercolumn_list" CONSTRAINT "fk_rp520yoe4qk3x4joe6114js" FOREIGN KEY (listbasicordercolumn_id) REFERENCES listbasicordercolumn(id)

jpatest=# \d listbasicordercolumn_list
           Table "public.listbasicordercolumn_list"
         Column          |          Type          | Modifiers 
-------------------------+------------------------+-----------
 listbasicordercolumn_id | bigint                 | not null
 list                    | character varying(255) | 
 list_order              | integer                | not null
Indexes:
    "listbasicordercolumn_list_pkey" PRIMARY KEY, btree (listbasicordercolumn_id, list_order)
Foreign-key constraints:
    "fk_rp520yoe4qk3x4joe6114js" FOREIGN KEY (listbasicordercolumn_id) REFERENCES listbasicordercolumn(id)

Entry data

log

16:29:32,747 DEBUG [org.hibernate.SQL] (default task-2) insert into ListBasicOrderColumn (id) values (?)
16:29:32,748 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-2) binding parameter [1] as [BIGINT] - [1]
16:29:32,749 DEBUG [org.hibernate.SQL] (default task-2) insert into ListBasicOrderColumn_list (ListBasicOrderColumn_id, list_ORDER, list) values (?, ?, ?)
16:29:32,749 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-2) binding parameter [1] as [BIGINT] - [1]
16:29:32,749 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-2) binding parameter [2] as [INTEGER] - [0]
16:29:32,749 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-2) binding parameter [3] as [VARCHAR] - [hoge]
16:29:32,750 DEBUG [org.hibernate.SQL] (default task-2) insert into ListBasicOrderColumn_list (ListBasicOrderColumn_id, list_ORDER, list) values (?, ?, ?)
16:29:32,750 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-2) binding parameter [1] as [BIGINT] - [1]
16:29:32,751 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-2) binding parameter [2] as [INTEGER] - [1]
16:29:32,751 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-2) binding parameter [3] as [VARCHAR] - [hoge]
16:29:32,751 DEBUG [org.hibernate.SQL] (default task-2) insert into ListBasicOrderColumn_list (ListBasicOrderColumn_id, list_ORDER, list) values (?, ?, ?)
16:29:32,751 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-2) binding parameter [1] as [BIGINT] - [1]
16:29:32,751 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-2) binding parameter [2] as [INTEGER] - [2]
16:29:32,752 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-2) binding parameter [3] as [VARCHAR] - [hige]

table

jpatest=# select * from listbasicordercolumn;
 id 
----
  1
(1 row)

jpatest=# select * from listbasicordercolumn_list order by list_order;
 listbasicordercolumn_id | list | list_order 
-------------------------+------+------------
                       1 | hoge |          0
                       1 | hoge |          1
                       1 | hige |          2
(3 rows)

jpatest=# 

Find

16:39:29,863 DEBUG [org.hibernate.SQL] (default task-2) select listbasico0_.id as id1_2_0_ from ListBasicOrderColumn listbasico0_ where listbasico0_.id=?
16:39:29,864 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-2) binding parameter [1] as [BIGINT] - [1]
16:39:29,865 DEBUG [org.hibernate.SQL] (default task-2) select list0_.ListBasicOrderColumn_id as ListBasi1_2_0_, list0_.list as list2_3_0_, list0_.list_ORDER as list_ORD3_0_ from ListBasicOrderColumn_list list0_ where list0_.ListBasicOrderColumn_id=?
16:39:29,865 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-2) binding parameter [1] as [BIGINT] - [1]
16:39:29,865 FINE  [org.nailedtothex.jpatest.list.ListBasicOrderColumnTestDataManipulator] (default task-2) find(): [hoge, hoge, hige]
  • List returned with correct order while there is no ORDER BY in the select clause.
  • I guess that every rows have its order number, so they doesn't need to got sorted at database side.

Add

log

16:46:43,469 DEBUG [org.hibernate.SQL] (default task-6) select listbasico0_.id as id1_2_0_ from ListBasicOrderColumn listbasico0_ where listbasico0_.id=?
16:46:43,469 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [1] as [BIGINT] - [1]
16:46:43,470 DEBUG [org.hibernate.SQL] (default task-6) select list0_.ListBasicOrderColumn_id as ListBasi1_2_0_, list0_.list as list2_3_0_, list0_.list_ORDER as list_ORD3_0_ from ListBasicOrderColumn_list list0_ where list0_.ListBasicOrderColumn_id=?
16:46:43,470 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [1] as [BIGINT] - [1]
16:46:43,474 DEBUG [org.hibernate.SQL] (default task-6) update ListBasicOrderColumn_list set list=? where ListBasicOrderColumn_id=? and list_ORDER=?
16:46:43,475 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [1] as [VARCHAR] - [hige]
16:46:43,475 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [2] as [BIGINT] - [1]
16:46:43,475 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [3] as [INTEGER] - [1]
16:46:43,475 DEBUG [org.hibernate.SQL] (default task-6) update ListBasicOrderColumn_list set list=? where ListBasicOrderColumn_id=? and list_ORDER=?
16:46:43,475 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [1] as [VARCHAR] - [hoge]
16:46:43,476 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [2] as [BIGINT] - [1]
16:46:43,476 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [3] as [INTEGER] - [2]
16:46:43,476 DEBUG [org.hibernate.SQL] (default task-6) insert into ListBasicOrderColumn_list (ListBasicOrderColumn_id, list_ORDER, list) values (?, ?, ?)
16:46:43,476 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [1] as [BIGINT] - [1]
16:46:43,476 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [2] as [INTEGER] - [3]
16:46:43,476 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-6) binding parameter [3] as [VARCHAR] - [hige]

table

jpatest=# select * from listbasicordercolumn_list order by list_order;
 listbasicordercolumn_id | list | list_order 
-------------------------+------+------------
                       1 | hoge |          0
                       1 | hige |          1
                       1 | hoge |          2
                       1 | hige |          3
(4 rows)

jpatest=# 
  • Tried to add a element with index 1, it works correctly.

Remove

log

16:52:52,834 DEBUG [org.hibernate.SQL] (default task-4) select listbasico0_.id as id1_2_0_ from ListBasicOrderColumn listbasico0_ where listbasico0_.id=?
16:52:52,834 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-4) binding parameter [1] as [BIGINT] - [1]
16:52:52,835 DEBUG [org.hibernate.SQL] (default task-4) select list0_.ListBasicOrderColumn_id as ListBasi1_2_0_, list0_.list as list2_3_0_, list0_.list_ORDER as list_ORD3_0_ from ListBasicOrderColumn_list list0_ where list0_.ListBasicOrderColumn_id=?
16:52:52,835 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-4) binding parameter [1] as [BIGINT] - [1]
16:52:52,841 DEBUG [org.hibernate.SQL] (default task-4) delete from ListBasicOrderColumn_list where ListBasicOrderColumn_id=? and list_ORDER=?
16:52:52,841 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-4) binding parameter [1] as [BIGINT] - [1]
16:52:52,841 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-4) binding parameter [2] as [INTEGER] - [2]
16:52:52,842 DEBUG [org.hibernate.SQL] (default task-4) update ListBasicOrderColumn_list set list=? where ListBasicOrderColumn_id=? and list_ORDER=?
16:52:52,842 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-4) binding parameter [1] as [VARCHAR] - [hige]
16:52:52,842 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-4) binding parameter [2] as [BIGINT] - [1]
16:52:52,842 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-4) binding parameter [3] as [INTEGER] - [1]

table

jpatest=# select * from listbasicordercolumn_list order by list_order;
 listbasicordercolumn_id | list | list_order 
-------------------------+------+------------
                       1 | hoge |          0
                       1 | hige |          1
(2 rows)

Swap

log

16:58:05,240 DEBUG [org.hibernate.SQL] (default task-11) select listbasico0_.id as id1_2_0_ from ListBasicOrderColumn listbasico0_ where listbasico0_.id=?
16:58:05,241 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-11) binding parameter [1] as [BIGINT] - [1]
16:58:05,242 DEBUG [org.hibernate.SQL] (default task-11) select list0_.ListBasicOrderColumn_id as ListBasi1_2_0_, list0_.list as list2_3_0_, list0_.list_ORDER as list_ORD3_0_ from ListBasicOrderColumn_list list0_ where list0_.ListBasicOrderColumn_id=?
16:58:05,243 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-11) binding parameter [1] as [BIGINT] - [1]
16:58:05,245 FINE  [org.nailedtothex.jpatest.list.ListBasicOrderColumnTestDataManipulator] (default task-11) swap(): [hige, hoge, hoge]
16:58:05,248 DEBUG [org.hibernate.SQL] (default task-11) update ListBasicOrderColumn_list set list=? where ListBasicOrderColumn_id=? and list_ORDER=?
16:58:05,248 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-11) binding parameter [1] as [VARCHAR] - [hige]
16:58:05,248 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-11) binding parameter [2] as [BIGINT] - [1]
16:58:05,248 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-11) binding parameter [3] as [INTEGER] - [0]
16:58:05,249 DEBUG [org.hibernate.SQL] (default task-11) update ListBasicOrderColumn_list set list=? where ListBasicOrderColumn_id=? and list_ORDER=?
16:58:05,249 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-11) binding parameter [1] as [VARCHAR] - [hoge]
16:58:05,249 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-11) binding parameter [2] as [BIGINT] - [1]
16:58:05,249 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-11) binding parameter [3] as [INTEGER] - [2]

table

jpatest=# select * from listbasicordercolumn_list order by list_order;
 listbasicordercolumn_id | list | list_order 
-------------------------+------+------------
                       1 | hige |          0
                       1 | hoge |          1
                       1 | hoge |          2
(3 rows)

List<Embeddable>

Schema

jpatest=# \d listembeddableparent
Table "public.listembeddableparent"
 Column |  Type  | Modifiers 
--------+--------+-----------
 id     | bigint | not null
Indexes:
    "listembeddableparent_pkey" PRIMARY KEY, btree (id)
Referenced by:
    TABLE "listembeddableparent_listembeddablechilds" CONSTRAINT "fk_owld92ex87wavc8ncap74eqk2" FOREIGN KEY (listembeddableparent_id) REFERENCES listembeddableparent(id)

jpatest=# \d listembeddableparent_listembeddablechilds
    Table "public.listembeddableparent_listembeddablechilds"
           Column           |          Type          | Modifiers 
----------------------------+------------------------+-----------
 listembeddableparent_id    | bigint                 | not null
 embfield1                  | character varying(255) | 
 embfield2                  | character varying(255) | 
 listembeddablechilds_order | integer                | not null
Indexes:
    "listembeddableparent_listembeddablechilds_pkey" PRIMARY KEY, btree (listembeddableparent_id, listembeddablechilds_order)
Foreign-key constraints:
    "fk_owld92ex87wavc8ncap74eqk2" FOREIGN KEY (listembeddableparent_id) REFERENCES listembeddableparent(id)

jpatest=# 

Entry data

log

17:10:16,833 DEBUG [org.hibernate.SQL] (default task-13) insert into ListEmbeddableParent (id) values (?)
17:10:16,834 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-13) binding parameter [1] as [BIGINT] - [1]
17:10:16,836 DEBUG [org.hibernate.SQL] (default task-13) insert into ListEmbeddableParent_listEmbeddableChilds (ListEmbeddableParent_id, listEmbeddableChilds_ORDER, embField1, embField2) values (?, ?, ?, ?)
17:10:16,836 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-13) binding parameter [1] as [BIGINT] - [1]
17:10:16,836 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-13) binding parameter [2] as [INTEGER] - [0]
17:10:16,836 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-13) binding parameter [3] as [VARCHAR] - [child1field1]
17:10:16,836 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-13) binding parameter [4] as [VARCHAR] - [child1field2]
17:10:16,840 DEBUG [org.hibernate.SQL] (default task-13) insert into ListEmbeddableParent_listEmbeddableChilds (ListEmbeddableParent_id, listEmbeddableChilds_ORDER, embField1, embField2) values (?, ?, ?, ?)
17:10:16,840 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-13) binding parameter [1] as [BIGINT] - [1]
17:10:16,840 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-13) binding parameter [2] as [INTEGER] - [1]
17:10:16,840 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-13) binding parameter [3] as [VARCHAR] - [child2field1]
17:10:16,840 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-13) binding parameter [4] as [VARCHAR] - [child2field2]
17:10:16,841 DEBUG [org.hibernate.SQL] (default task-13) insert into ListEmbeddableParent_listEmbeddableChilds (ListEmbeddableParent_id, listEmbeddableChilds_ORDER, embField1, embField2) values (?, ?, ?, ?)
17:10:16,841 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-13) binding parameter [1] as [BIGINT] - [1]
17:10:16,841 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-13) binding parameter [2] as [INTEGER] - [2]
17:10:16,842 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-13) binding parameter [3] as [VARCHAR] - [child3field1]
17:10:16,842 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-13) binding parameter [4] as [VARCHAR] - [child3field2]

table

jpatest=# select * from listembeddableparent;
 id 
----
  1
(1 row)

jpatest=# select * from listembeddableparent_listembeddablechilds order by listembeddablechilds_order;
 listembeddableparent_id |  embfield1   |  embfield2   | listembeddablechilds_order 
-------------------------+--------------+--------------+----------------------------
                       1 | child1field1 | child1field2 |                          0
                       1 | child2field1 | child2field2 |                          1
                       1 | child3field1 | child3field2 |                          2
(3 rows)

Find

17:32:03,442 DEBUG [org.hibernate.SQL] (default task-7) select listembedd0_.id as id1_4_0_ from ListEmbeddableParent listembedd0_ where listembedd0_.id=?
17:32:03,443 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-7) binding parameter [1] as [BIGINT] - [1]
17:32:03,444 DEBUG [org.hibernate.SQL] (default task-7) select listembedd0_.ListEmbeddableParent_id as ListEmbe1_4_0_, listembedd0_.embField1 as embField2_5_0_, listembedd0_.embField2 as embField3_5_0_, listembedd0_.listEmbeddableChilds_ORDER as listEmbe4_0_ from ListEmbeddableParent_listEmbeddableChilds listembedd0_ where listembedd0_.ListEmbeddableParent_id=?
17:32:03,444 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-7) binding parameter [1] as [BIGINT] - [1]
17:32:03,443 FINE  [org.nailedtothex.jpatest.list.ListEmbeddableTestDataManipulator] (default task-7) find(): [ListEmbeddableChild [embField1=child1field1, embField2=child1field2], ListEmbeddableChild [embField1=child2field1, embField2=child2field2], ListEmbeddableChild [embField1=child3field1, embField2=child3field2]]

Add

log

17:42:47,823 DEBUG [org.hibernate.SQL] (default task-3) select listembedd0_.id as id1_4_0_ from ListEmbeddableParent listembedd0_ where listembedd0_.id=?
17:42:47,824 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-3) binding parameter [1] as [BIGINT] - [1]
17:42:47,825 DEBUG [org.hibernate.SQL] (default task-3) select listembedd0_.ListEmbeddableParent_id as ListEmbe1_4_0_, listembedd0_.embField1 as embField2_5_0_, listembedd0_.embField2 as embField3_5_0_, listembedd0_.listEmbeddableChilds_ORDER as listEmbe4_0_ from ListEmbeddableParent_listEmbeddableChilds listembedd0_ where listembedd0_.ListEmbeddableParent_id=?
17:42:47,826 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-3) binding parameter [1] as [BIGINT] - [1]
17:42:47,830 DEBUG [org.hibernate.SQL] (default task-3) update ListEmbeddableParent_listEmbeddableChilds set embField1=?, embField2=? where ListEmbeddableParent_id=? and listEmbeddableChilds_ORDER=?
17:42:47,830 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-3) binding parameter [1] as [VARCHAR] - [child4field1]
17:42:47,830 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-3) binding parameter [2] as [VARCHAR] - [child4field2]
17:42:47,830 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-3) binding parameter [3] as [BIGINT] - [1]
17:42:47,830 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-3) binding parameter [4] as [INTEGER] - [2]
17:42:47,831 DEBUG [org.hibernate.SQL] (default task-3) insert into ListEmbeddableParent_listEmbeddableChilds (ListEmbeddableParent_id, listEmbeddableChilds_ORDER, embField1, embField2) values (?, ?, ?, ?)
17:42:47,831 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-3) binding parameter [1] as [BIGINT] - [1]
17:42:47,831 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-3) binding parameter [2] as [INTEGER] - [3]
17:42:47,831 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-3) binding parameter [3] as [VARCHAR] - [child3field1]
17:42:47,831 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-3) binding parameter [4] as [VARCHAR] - [child3field2]

table

jpatest=# select * from listembeddableparent_listembeddablechilds order by listembeddablechilds_order;
 listembeddableparent_id |  embfield1   |  embfield2   | listembeddablechilds_order 
-------------------------+--------------+--------------+----------------------------
                       1 | child1field1 | child1field2 |                          0
                       1 | child2field1 | child2field2 |                          1
                       1 | child4field1 | child4field2 |                          2
                       1 | child3field1 | child3field2 |                          3
(4 rows)

Remove

log

17:47:20,736 DEBUG [org.hibernate.SQL] (default task-14) select listembedd0_.id as id1_4_0_ from ListEmbeddableParent listembedd0_ where listembedd0_.id=?
17:47:20,737 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [1] as [BIGINT] - [1]
17:47:20,738 DEBUG [org.hibernate.SQL] (default task-14) select listembedd0_.ListEmbeddableParent_id as ListEmbe1_4_0_, listembedd0_.embField1 as embField2_5_0_, listembedd0_.embField2 as embField3_5_0_, listembedd0_.listEmbeddableChilds_ORDER as listEmbe4_0_ from ListEmbeddableParent_listEmbeddableChilds listembedd0_ where listembedd0_.ListEmbeddableParent_id=?
17:47:20,738 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [1] as [BIGINT] - [1]
17:47:20,744 DEBUG [org.hibernate.SQL] (default task-14) delete from ListEmbeddableParent_listEmbeddableChilds where ListEmbeddableParent_id=? and listEmbeddableChilds_ORDER=?
17:47:20,744 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [1] as [BIGINT] - [1]
17:47:20,744 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [2] as [INTEGER] - [2]
17:47:20,745 DEBUG [org.hibernate.SQL] (default task-14) update ListEmbeddableParent_listEmbeddableChilds set embField1=?, embField2=? where ListEmbeddableParent_id=? and listEmbeddableChilds_ORDER=?
17:47:20,745 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [1] as [VARCHAR] - [child3field1]
17:47:20,745 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [2] as [VARCHAR] - [child3field2]
17:47:20,745 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [3] as [BIGINT] - [1]
17:47:20,745 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-14) binding parameter [4] as [INTEGER] - [1]

table

jpatest=# select * from listembeddableparent_listembeddablechilds order by listembeddablechilds_order;
 listembeddableparent_id |  embfield1   |  embfield2   | listembeddablechilds_order 
-------------------------+--------------+--------------+----------------------------
                       1 | child1field1 | child1field2 |                          0
                       1 | child3field1 | child3field2 |                          1
(2 rows)

Update

log

17:51:19,995 DEBUG [org.hibernate.SQL] (default task-7) select listembedd0_.id as id1_4_0_ from ListEmbeddableParent listembedd0_ where listembedd0_.id=?
17:51:19,996 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-7) binding parameter [1] as [BIGINT] - [1]
17:51:19,997 DEBUG [org.hibernate.SQL] (default task-7) select listembedd0_.ListEmbeddableParent_id as ListEmbe1_4_0_, listembedd0_.embField1 as embField2_5_0_, listembedd0_.embField2 as embField3_5_0_, listembedd0_.listEmbeddableChilds_ORDER as listEmbe4_0_ from ListEmbeddableParent_listEmbeddableChilds listembedd0_ where listembedd0_.ListEmbeddableParent_id=?
17:51:19,997 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-7) binding parameter [1] as [BIGINT] - [1]
17:51:20,001 DEBUG [org.hibernate.SQL] (default task-7) update ListEmbeddableParent_listEmbeddableChilds set embField1=?, embField2=? where ListEmbeddableParent_id=? and listEmbeddableChilds_ORDER=?
17:51:20,001 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-7) binding parameter [1] as [VARCHAR] - [child2field1-updated]
17:51:20,002 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-7) binding parameter [2] as [VARCHAR] - [child2field2-updated]
17:51:20,002 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-7) binding parameter [3] as [BIGINT] - [1]
17:51:20,002 TRACE [org.hibernate.type.descriptor.sql.BasicBinder] (default task-7) binding parameter [4] as [INTEGER] - [1]

table

jpatest=# select * from listembeddableparent_listembeddablechilds order by listembeddablechilds_order;
 listembeddableparent_id |      embfield1       |      embfield2       | listembeddablechilds_order 
-------------------------+----------------------+----------------------+----------------------------
                       1 | child1field1         | child1field2         |                          0
                       1 | child2field1-updated | child2field2-updated |                          1
                       1 | child3field1         | child3field2         |                          2
(3 rows)

Remarks

  • It's so convenient for prototypes.
  • Maybe also good for small data sets.

References



No one has commented yet.

Leave a Comment

HTML Syntax: NOT allowed