Skip to content

Commit 47a7f54

Browse files
committed
add a test for a custom type with constructor on @ElenentCollection
1 parent c8868e6 commit 47a7f54

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/mapping/basic/bitset/MetaUserTypeTest.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55
package org.hibernate.orm.test.mapping.basic.bitset;
66

7+
import jakarta.persistence.ElementCollection;
78
import jakarta.persistence.Entity;
89
import jakarta.persistence.GeneratedValue;
910
import jakarta.persistence.Id;
@@ -21,6 +22,8 @@
2122
import java.sql.ResultSet;
2223
import java.sql.SQLException;
2324
import java.time.Period;
25+
import java.util.ArrayList;
26+
import java.util.List;
2427
import java.util.Objects;
2528

2629
import static java.lang.Integer.parseInt;
@@ -30,7 +33,7 @@
3033
import static java.sql.Types.VARCHAR;
3134
import static org.junit.jupiter.api.Assertions.assertEquals;
3235

33-
@Jpa(annotatedClasses = MetaUserTypeTest.Thing.class)
36+
@Jpa(annotatedClasses = {MetaUserTypeTest.Thing.class, MetaUserTypeTest.Things.class})
3437
public 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
5269
long id;
@@ -56,7 +73,16 @@ public class MetaUserTypeTest {
5673
Period 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)
6288
public @interface TimePeriod {

0 commit comments

Comments
 (0)