Skip to content

Commit 23ad2b4

Browse files
allow null value persistence and retrieval (#111)
HIBERNATE-48
1 parent eece9cb commit 23ad2b4

19 files changed

+337
-378
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ assertj = "3.27.3"
1818
google-errorprone-core = "2.36.0"
1919
nullaway = "0.12.4"
2020
jspecify = "1.0.0"
21-
hibernate-orm = "6.6.9.Final"
21+
hibernate-orm = "6.6.23.Final"
2222
mongo-java-driver-sync = "5.3.1"
2323
slf4j-api = "2.0.16"
2424
logback-classic = "1.5.16"

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

Lines changed: 57 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.mongodb.hibernate;
1818

1919
import static com.mongodb.hibernate.MongoTestAssertions.assertEq;
20+
import static java.util.Arrays.asList;
2021
import static org.assertj.core.api.Assertions.assertThat;
2122
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2223
import static org.hibernate.cfg.AvailableSettings.WRAPPER_ARRAY_HANDLING;
@@ -47,7 +48,6 @@
4748
import org.hibernate.testing.orm.junit.SessionFactoryScope;
4849
import org.hibernate.testing.orm.junit.SessionFactoryScopeAware;
4950
import org.hibernate.testing.orm.junit.Setting;
50-
import org.junit.jupiter.api.Disabled;
5151
import org.junit.jupiter.api.Nested;
5252
import org.junit.jupiter.api.Test;
5353
import org.junit.jupiter.api.extension.ExtendWith;
@@ -78,33 +78,32 @@ public void injectSessionFactoryScope(SessionFactoryScope sessionFactoryScope) {
7878
void testArrayAndCollectionValues() {
7979
var item = new ItemWithArrayAndCollectionValues(
8080
1,
81-
// TODO-HIBERNATE-48 sprinkle on `null` array/collection elements
8281
new byte[] {2, 3},
8382
new char[] {'s', 't', 'r'},
8483
new int[] {5},
8584
new long[] {Long.MAX_VALUE, 6},
8685
new double[] {Double.MAX_VALUE},
8786
new boolean[] {true},
88-
new Character[] {'s', 't', 'r'},
89-
new Integer[] {7},
90-
new Long[] {8L},
91-
new Double[] {9.1d},
92-
new Boolean[] {true},
93-
new String[] {"str"},
94-
new BigDecimal[] {BigDecimal.valueOf(10.1)},
95-
new ObjectId[] {new ObjectId("000000000000000000000001")},
87+
new Character[] {'s', null, 't', 'r'},
88+
new Integer[] {null, 7},
89+
new Long[] {8L, null},
90+
new Double[] {9.1d, null},
91+
new Boolean[] {true, null},
92+
new String[] {null, "str"},
93+
new BigDecimal[] {null, BigDecimal.valueOf(10.1)},
94+
new ObjectId[] {new ObjectId("000000000000000000000001"), null},
9695
new StructAggregateEmbeddableIntegrationTests.Single[] {
97-
new StructAggregateEmbeddableIntegrationTests.Single(1)
96+
new StructAggregateEmbeddableIntegrationTests.Single(1), null
9897
},
99-
List.of('s', 't', 'r'),
100-
List.of(5),
101-
List.of(Long.MAX_VALUE, 6L),
102-
List.of(Double.MAX_VALUE),
103-
List.of(true),
104-
List.of("str"),
105-
List.of(BigDecimal.valueOf(10.1)),
106-
List.of(new ObjectId("000000000000000000000001")),
107-
List.of(new StructAggregateEmbeddableIntegrationTests.Single(1)));
98+
asList('s', 't', null, 'r'),
99+
asList(null, 5),
100+
asList(Long.MAX_VALUE, null, 6L),
101+
asList(null, Double.MAX_VALUE),
102+
asList(null, true),
103+
asList("str", null),
104+
asList(BigDecimal.valueOf(10.1), null),
105+
asList(null, new ObjectId("000000000000000000000001")),
106+
asList(new StructAggregateEmbeddableIntegrationTests.Single(1), null));
108107
sessionFactoryScope.inTransaction(session -> session.persist(item));
109108
assertCollectionContainsExactly(
110109
"""
@@ -116,24 +115,24 @@ void testArrayAndCollectionValues() {
116115
longs: [{$numberLong: "9223372036854775807"}, {$numberLong: "6"}],
117116
doubles: [{$numberDouble: "1.7976931348623157E308"}],
118117
booleans: [true],
119-
boxedChars: ["s", "t", "r"],
120-
boxedInts: [7],
121-
boxedLongs: [{$numberLong: "8"}],
122-
boxedDoubles: [{$numberDouble: "9.1"}],
123-
boxedBooleans: [true],
124-
strings: ["str"],
125-
bigDecimals: [{$numberDecimal: "10.1"}],
126-
objectIds: [{$oid: "000000000000000000000001"}],
127-
structAggregateEmbeddables: [{a: 1}],
128-
charsCollection: ["s", "t", "r"],
129-
intsCollection: [5],
130-
longsCollection: [{$numberLong: "9223372036854775807"}, {$numberLong: "6"}],
131-
doublesCollection: [{$numberDouble: "1.7976931348623157E308"}],
132-
booleansCollection: [true],
133-
stringsCollection: ["str"],
134-
bigDecimalsCollection: [{$numberDecimal: "10.1"}],
135-
objectIdsCollection: [{$oid: "000000000000000000000001"}],
136-
structAggregateEmbeddablesCollection: [{a: 1}]
118+
boxedChars: ["s", null, "t", "r"],
119+
boxedInts: [null, 7],
120+
boxedLongs: [{$numberLong: "8"}, null],
121+
boxedDoubles: [{$numberDouble: "9.1"}, null],
122+
boxedBooleans: [true, null],
123+
strings: [null, "str"],
124+
bigDecimals: [null, {$numberDecimal: "10.1"}],
125+
objectIds: [{$oid: "000000000000000000000001"}, null],
126+
structAggregateEmbeddables: [{a: 1}, null],
127+
charsCollection: ["s", "t", null, "r"],
128+
intsCollection: [null, 5],
129+
longsCollection: [{$numberLong: "9223372036854775807"}, null, {$numberLong: "6"}],
130+
doublesCollection: [null, {$numberDouble: "1.7976931348623157E308"}],
131+
booleansCollection: [null, true],
132+
stringsCollection: ["str", null],
133+
bigDecimalsCollection: [{$numberDecimal: "10.1"}, null],
134+
objectIdsCollection: [null, {$oid: "000000000000000000000001"}],
135+
structAggregateEmbeddablesCollection: [{a: 1}, null]
137136
}
138137
""");
139138
var loadedItem = sessionFactoryScope.fromTransaction(
@@ -158,24 +157,24 @@ void testArrayAndCollectionValues() {
158157
longs: [{$numberLong: "9223372036854775807"}, {$numberLong: "-6"}],
159158
doubles: [{$numberDouble: "1.7976931348623157E308"}],
160159
booleans: [true],
161-
boxedChars: ["s", "t", "r"],
162-
boxedInts: [7],
163-
boxedLongs: [{$numberLong: "8"}],
164-
boxedDoubles: [{$numberDouble: "9.1"}],
165-
boxedBooleans: [true],
166-
strings: ["str"],
167-
bigDecimals: [{$numberDecimal: "10.1"}],
168-
objectIds: [{$oid: "000000000000000000000002"}],
169-
structAggregateEmbeddables: [{a: 1}],
170-
charsCollection: ["s", "t", "r"],
171-
intsCollection: [5],
172-
longsCollection: [{$numberLong: "9223372036854775807"}, {$numberLong: "-6"}],
173-
doublesCollection: [{$numberDouble: "1.7976931348623157E308"}],
174-
booleansCollection: [true],
175-
stringsCollection: ["str"],
176-
bigDecimalsCollection: [{$numberDecimal: "10.1"}],
177-
objectIdsCollection: [{$oid: "000000000000000000000001"}],
178-
structAggregateEmbeddablesCollection: [{a: 1}]
160+
boxedChars: ["s", null, "t", "r"],
161+
boxedInts: [null, 7],
162+
boxedLongs: [{$numberLong: "8"}, null],
163+
boxedDoubles: [{$numberDouble: "9.1"}, null],
164+
boxedBooleans: [true, null],
165+
strings: [null, "str"],
166+
bigDecimals: [null, {$numberDecimal: "10.1"}],
167+
objectIds: [{$oid: "000000000000000000000002"}, null],
168+
structAggregateEmbeddables: [{a: 1}, null],
169+
charsCollection: ["s", "t", null, "r"],
170+
intsCollection: [null, 5],
171+
longsCollection: [{$numberLong: "9223372036854775807"}, null, {$numberLong: "-6"}],
172+
doublesCollection: [null, {$numberDouble: "1.7976931348623157E308"}],
173+
booleansCollection: [null, true],
174+
stringsCollection: ["str", null],
175+
bigDecimalsCollection: [{$numberDecimal: "10.1"}, null],
176+
objectIdsCollection: [null, {$oid: "000000000000000000000001"}],
177+
structAggregateEmbeddablesCollection: [{a: 1}, null]
179178
}
180179
""");
181180
loadedItem = sessionFactoryScope.fromTransaction(
@@ -248,7 +247,6 @@ void testArrayAndCollectionEmptyValues() {
248247
}
249248

250249
@Test
251-
@Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
252250
void testArrayAndCollectionNullValues() {
253251
var item = new ItemWithArrayAndCollectionValues(
254252
1, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
@@ -410,7 +408,6 @@ void testArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingArraysAndColl
410408
* @see StructAggregateEmbeddableIntegrationTests#testNestedValueHavingNullArraysAndCollections()
411409
*/
412410
@Test
413-
@Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
414411
public void testArrayAndCollectionValuesOfEmptyStructAggregateEmbeddables() {
415412
var emptyStructAggregateEmbeddable = new ArraysAndCollections(
416413
null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
@@ -597,16 +594,12 @@ static class ItemWithArrayAndCollectionValuesOfStructAggregateEmbeddablesHavingA
597594

598595
@Nested
599596
class Unsupported {
600-
/**
601-
* The {@link ClassCastException} caught here manifests a Hibernate ORM bug. The issue goes away if the
602-
* {@link ItemWithBoxedBytesArrayValue#bytes} field is removed. Otherwise, the behavior of this test should have
603-
* been equivalent to {@link #testBytesCollectionValue()}.
604-
*/
597+
605598
@Test
606599
void testBoxedBytesArrayValue() {
607600
var item = new ItemWithBoxedBytesArrayValue(1, new byte[] {1}, new Byte[] {2});
608601
assertThatThrownBy(() -> sessionFactoryScope.inTransaction(session -> session.persist(item)))
609-
.isInstanceOf(ClassCastException.class);
602+
.hasCauseInstanceOf(SQLFeatureNotSupportedException.class);
610603
}
611604

612605
@Test

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.hibernate.testing.orm.junit.SessionFactory;
3333
import org.hibernate.testing.orm.junit.SessionFactoryScope;
3434
import org.hibernate.testing.orm.junit.SessionFactoryScopeAware;
35-
import org.junit.jupiter.api.Disabled;
3635
import org.junit.jupiter.api.Nested;
3736
import org.junit.jupiter.api.Test;
3837
import org.junit.jupiter.api.extension.ExtendWith;
@@ -97,7 +96,6 @@ void testSimpleEntityInsertion() {
9796
}
9897

9998
@Test
100-
@Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
10199
void testEntityWithNullFieldValuesInsertion() {
102100
sessionFactoryScope.inTransaction(session -> session.persist(new Item(
103101
1,
@@ -218,7 +216,6 @@ void testSimpleUpdate() {
218216
}
219217

220218
@Test
221-
@Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
222219
void testSimpleUpdateWithNullFieldValues() {
223220
sessionFactoryScope.inTransaction(session -> {
224221
var item = new Item(
@@ -290,7 +287,6 @@ void testDynamicUpdate() {
290287
}
291288

292289
@Test
293-
@Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
294290
void testDynamicUpdateWithNullFieldValues() {
295291
sessionFactoryScope.inTransaction(session -> {
296292
var item = new ItemDynamicallyUpdated(1, false, true);
@@ -337,7 +333,6 @@ void testFindByPrimaryKey() {
337333
}
338334

339335
@Test
340-
@Disabled("TODO-HIBERNATE-48 https://jira.mongodb.org/browse/HIBERNATE-48 enable this test")
341336
void testFindByPrimaryKeyWithNullFieldValues() {
342337
var item = new Item(
343338
1, 'c', 1, Long.MAX_VALUE, Double.MAX_VALUE, true, null, null, null, null, null, null, null, null);

0 commit comments

Comments
 (0)