44 */
55package org .hibernate .orm .test .mapping .basic .bitset ;
66
7+ import jakarta .persistence .ElementCollection ;
78import jakarta .persistence .Entity ;
89import jakarta .persistence .GeneratedValue ;
910import jakarta .persistence .Id ;
2122import java .sql .ResultSet ;
2223import java .sql .SQLException ;
2324import java .time .Period ;
25+ import java .util .ArrayList ;
26+ import java .util .List ;
2427import java .util .Objects ;
2528
2629import static java .lang .Integer .parseInt ;
3033import static java .sql .Types .VARCHAR ;
3134import static org .junit .jupiter .api .Assertions .assertEquals ;
3235
33- @ Jpa (annotatedClasses = MetaUserTypeTest .Thing .class )
36+ @ Jpa (annotatedClasses = { MetaUserTypeTest .Thing .class , MetaUserTypeTest . Things . class } )
3437public class MetaUserTypeTest {
3538
3639@ Test void test (EntityManagerFactoryScope scope ) {
@@ -47,6 +50,20 @@ public class MetaUserTypeTest {
4750} );
4851}
4952
53+ @ Test void testCollection (EntityManagerFactoryScope scope ) {
54+ scope .inTransaction ( em -> {
55+ Things things = new Things ();
56+ things .periods .add ( Period .of ( 1 , 2 , 3 ) );
57+ things .days .add ( Period .ofDays ( 42 ) );
58+ em .persist ( things );
59+ } );
60+ scope .inTransaction ( em -> {
61+ Things things = em .find ( Things .class , 1 );
62+ assertEquals ( Period .of ( 1 , 2 , 3 ), things .periods .get ( 0 ) );
63+ assertEquals ( Period .ofDays ( 42 ), things .days .get ( 0 ) );
64+ } );
65+ }
66+
5067@ Entity static class Thing {
5168@ Id @ GeneratedValue
5269long id ;
@@ -56,7 +73,16 @@ public class MetaUserTypeTest {
5673Period days ;
5774}
5875
59- @ Type (PeriodType . class )
76+ @ Entity static class Things {
77+ @ Id @ GeneratedValue
78+ long id ;
79+ @ TimePeriod @ ElementCollection
80+ List <Period > periods = new ArrayList <>();
81+ @ TimePeriod (days = true ) @ ElementCollection
82+ List <Period > days = new ArrayList <>();
83+ }
84+
85+ @ Type (PeriodType .class )
6086@ Target ({METHOD , FIELD })
6187@ Retention (RUNTIME )
6288public @interface TimePeriod {
0 commit comments