Skip to content

Commit e19bd11

Browse files
authored
Support arrays/collections mapping (#95)
HIBERNATE-58
1 parent 3bc4692 commit e19bd11

29 files changed

+2749
-366
lines changed

src/integrationTest/java/com/mongodb/hibernate/ArrayAndCollectionIntegrationTests.java

Lines changed: 773 additions & 0 deletions
Large diffs are not rendered by default.

src/integrationTest/java/com/mongodb/hibernate/BasicCrudIntegrationTests.java

Lines changed: 293 additions & 110 deletions
Large diffs are not rendered by default.

src/integrationTest/java/com/mongodb/hibernate/IdentifierIntegrationTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ class IdentifierIntegrationTests implements SessionFactoryScopeAware {
8787

8888
private SessionFactoryScope sessionFactoryScope;
8989

90+
@Override
91+
public void injectSessionFactoryScope(SessionFactoryScope sessionFactoryScope) {
92+
this.sessionFactoryScope = sessionFactoryScope;
93+
}
94+
9095
@Test
9196
void withSpaceAndDotAndMixedCase() {
9297
var item = new WithSpaceAndDotAndMixedCase();
@@ -197,11 +202,6 @@ void endingWithRightSquareBracket() {
197202
sessionFactoryScope.inTransaction(session -> session.find(EndingWithRightSquareBracket.class, item.id));
198203
}
199204

200-
@Override
201-
public void injectSessionFactoryScope(SessionFactoryScope sessionFactoryScope) {
202-
this.sessionFactoryScope = sessionFactoryScope;
203-
}
204-
205205
@Entity
206206
@Table(name = WithSpaceAndDotAndMixedCase.COLLECTION_NAME)
207207
static class WithSpaceAndDotAndMixedCase {

src/integrationTest/java/com/mongodb/hibernate/MongoTestAssertions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ public static void assertUsingRecursiveComparison(
4040
@Nullable Object actual,
4141
BiConsumer<RecursiveComparisonAssert<?>, Object> assertion) {
4242
assertion.accept(
43-
assertThat(expected)
43+
assertThat(actual)
4444
.usingRecursiveComparison()
4545
.usingOverriddenEquals()
4646
.withStrictTypeChecking(),
47-
actual);
47+
expected);
4848
}
4949

5050
/**

src/integrationTest/java/com/mongodb/hibernate/embeddable/EmbeddableIntegrationTests.java

Lines changed: 549 additions & 41 deletions
Large diffs are not rendered by default.

src/integrationTest/java/com/mongodb/hibernate/embeddable/StructAggregateEmbeddableIntegrationTests.java

Lines changed: 569 additions & 67 deletions
Large diffs are not rendered by default.

src/integrationTest/java/com/mongodb/hibernate/id/ObjectIdAsIdIntegrationTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class ObjectIdAsIdIntegrationTests implements SessionFactoryScopeAware {
5353

5454
private SessionFactoryScope sessionFactoryScope;
5555

56+
@Override
57+
public void injectSessionFactoryScope(SessionFactoryScope sessionFactoryScope) {
58+
this.sessionFactoryScope = sessionFactoryScope;
59+
}
60+
5661
@Test
5762
void insert() {
5863
var item = new Item();
@@ -70,11 +75,6 @@ void findById() {
7075
assertEquals(item.id, loadedItem.id);
7176
}
7277

73-
@Override
74-
public void injectSessionFactoryScope(SessionFactoryScope sessionFactoryScope) {
75-
this.sessionFactoryScope = sessionFactoryScope;
76-
}
77-
7878
@Nested
7979
class Generated {
8080
@Test

src/integrationTest/java/com/mongodb/hibernate/query/select/AbstractSelectionQueryIntegrationTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@ abstract class AbstractSelectionQueryIntegrationTests implements SessionFactoryS
4242

4343
private TestCommandListener testCommandListener;
4444

45-
SessionFactoryScope getSessionFactoryScope() {
46-
return sessionFactoryScope;
47-
}
48-
49-
TestCommandListener getTestCommandListener() {
50-
return testCommandListener;
51-
}
52-
5345
@Override
5446
public void injectSessionFactoryScope(SessionFactoryScope sessionFactoryScope) {
5547
this.sessionFactoryScope = sessionFactoryScope;
@@ -60,6 +52,14 @@ public void injectServiceRegistryScope(ServiceRegistryScope serviceRegistryScope
6052
this.testCommandListener = serviceRegistryScope.getRegistry().requireService(TestCommandListener.class);
6153
}
6254

55+
SessionFactoryScope getSessionFactoryScope() {
56+
return sessionFactoryScope;
57+
}
58+
59+
TestCommandListener getTestCommandListener() {
60+
return testCommandListener;
61+
}
62+
6363
<T> void assertSelectionQuery(
6464
String hql,
6565
Class<T> resultType,

src/integrationTest/java/com/mongodb/hibernate/query/select/SimpleSelectQueryIntegrationTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class SimpleSelectQueryIntegrationTests extends AbstractSelectionQueryIntegratio
3939

4040
@Nested
4141
class QueryTests {
42+
@BeforeEach
43+
void beforeEach() {
44+
getSessionFactoryScope().inTransaction(session -> testingContacts.forEach(session::persist));
45+
getTestCommandListener().clear();
46+
}
4247

4348
private static final List<Contact> testingContacts = List.of(
4449
new Contact(1, "Bob", 18, Country.USA),
@@ -56,12 +61,6 @@ private static List<Contact> getTestingContacts(int... ids) {
5661
.toList();
5762
}
5863

59-
@BeforeEach
60-
void beforeEach() {
61-
getSessionFactoryScope().inTransaction(session -> testingContacts.forEach(session::persist));
62-
getTestCommandListener().clear();
63-
}
64-
6564
@ParameterizedTest
6665
@ValueSource(booleans = {true, false})
6766
void testComparisonByEq(boolean fieldAsLhs) {

src/integrationTest/java/com/mongodb/hibernate/query/select/SortingSelectQueryIntegrationTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838

3939
@DomainModel(annotatedClasses = Book.class)
4040
class SortingSelectQueryIntegrationTests extends AbstractSelectionQueryIntegrationTests {
41+
@BeforeEach
42+
void beforeEach() {
43+
getSessionFactoryScope().inTransaction(session -> testingBooks.forEach(session::persist));
44+
getTestCommandListener().clear();
45+
}
4146

4247
private static final List<Book> testingBooks = List.of(
4348
new Book(1, "War and Peace", 1869, true),
@@ -55,12 +60,6 @@ private static List<Book> getBooksByIds(int... ids) {
5560
.toList();
5661
}
5762

58-
@BeforeEach
59-
void beforeEach() {
60-
getSessionFactoryScope().inTransaction(session -> testingBooks.forEach(session::persist));
61-
getTestCommandListener().clear();
62-
}
63-
6463
@ParameterizedTest
6564
@ValueSource(strings = {"ASC", "DESC"})
6665
void testOrderBySingleFieldWithoutTies(String sortDirection) {

0 commit comments

Comments
 (0)