Skip to content

Commit bfe9165

Browse files
committed
HHH-19596 Test case from example in Jira issue
1 parent 9bfabbd commit bfe9165

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.orm.test.array;
6+
7+
import jakarta.persistence.Embeddable;
8+
import jakarta.persistence.Entity;
9+
import jakarta.persistence.Id;
10+
import jakarta.persistence.Table;
11+
import org.hibernate.annotations.Struct;
12+
import org.hibernate.testing.orm.junit.*;
13+
import org.hibernate.testing.orm.junit.DialectFeatureChecks.SupportsStructAggregate;
14+
import org.hibernate.testing.orm.junit.DialectFeatureChecks.SupportsTypedArrays;
15+
import org.junit.jupiter.api.Test;
16+
17+
import java.util.Arrays;
18+
import java.util.List;
19+
20+
import static org.junit.jupiter.api.Assertions.assertEquals;
21+
import static org.junit.jupiter.api.Assertions.assertNull;
22+
23+
@SessionFactory
24+
@DomainModel(annotatedClasses = {
25+
StructArrayWithNullElementTestDemoTest.Book.class,
26+
StructArrayWithNullElementTestDemoTest.Author.class
27+
})
28+
@RequiresDialectFeature(feature = SupportsStructAggregate.class)
29+
@RequiresDialectFeature(feature = SupportsTypedArrays.class)
30+
class StructArrayWithNullElementTestDemoTest {
31+
32+
@Test
33+
void test(SessionFactoryScope scope) {
34+
scope.inTransaction( session -> {
35+
var book = new Book();
36+
book.id = 1;
37+
book.authors = Arrays.asList(
38+
new Author( "John", "Smith" ),
39+
null
40+
);
41+
session.persist( book );
42+
} );
43+
44+
scope.inSession( session -> {
45+
final var book = session.find( Book.class, 1 );
46+
assertEquals( 2, book.authors.size() );
47+
assertEquals( new Author( "John", "Smith" ), book.authors.get( 0 ) );
48+
assertNull( book.authors.get( 1 ) );
49+
} );
50+
}
51+
52+
@Entity(name = "Book")
53+
@Table(name = "books")
54+
static class Book {
55+
@Id
56+
int id;
57+
List<Author> authors;
58+
}
59+
60+
@Embeddable
61+
@Struct(name = "Author")
62+
record Author(String firstName, String lastName) {
63+
}
64+
}

0 commit comments

Comments
 (0)