Skip to content

Commit 90a4383

Browse files
committed
Merge branch 'main' into HIBERNATE-60
2 parents 5bc7050 + 193c5c7 commit 90a4383

File tree

39 files changed

+2221
-199
lines changed

39 files changed

+2221
-199
lines changed

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

Lines changed: 42 additions & 1 deletion
Large diffs are not rendered by default.

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

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import jakarta.persistence.SqlResultSetMapping;
3737
import jakarta.persistence.Table;
3838
import java.math.BigDecimal;
39+
import java.time.Instant;
3940
import org.bson.BsonDocument;
4041
import org.bson.conversions.Bson;
4142
import org.bson.types.ObjectId;
@@ -84,7 +85,8 @@ void testSimpleEntityInsertion() {
8485
true,
8586
"str",
8687
BigDecimal.valueOf(10.1),
87-
new ObjectId("000000000000000000000001"))));
88+
new ObjectId("000000000000000000000001"),
89+
Instant.parse("2024-01-01T10:00:00Z"))));
8890
assertCollectionContainsExactly(
8991
"""
9092
{
@@ -101,7 +103,8 @@ void testSimpleEntityInsertion() {
101103
boxedBoolean: true,
102104
string: "str",
103105
bigDecimal: {$numberDecimal: "10.1"},
104-
objectId: {$oid: "000000000000000000000001"}
106+
objectId: {$oid: "000000000000000000000001"},
107+
instant: {$date: "2024-01-01T10:00:00Z"}
105108
}
106109
""");
107110
}
@@ -122,6 +125,7 @@ void testEntityWithNullFieldValuesInsertion() {
122125
null,
123126
null,
124127
null,
128+
null,
125129
null)));
126130
assertCollectionContainsExactly(
127131
"""
@@ -139,7 +143,8 @@ void testEntityWithNullFieldValuesInsertion() {
139143
boxedBoolean: null,
140144
string: null,
141145
bigDecimal: null,
142-
objectId: null
146+
objectId: null,
147+
instant: null
143148
}
144149
""");
145150
}
@@ -166,7 +171,8 @@ void testSimpleDeletion() {
166171
true,
167172
"str",
168173
BigDecimal.valueOf(10.1),
169-
new ObjectId("000000000000000000000001"))));
174+
new ObjectId("000000000000000000000001"),
175+
Instant.parse("2024-01-01T10:00:00Z"))));
170176
assertThat(mongoCollection.find()).hasSize(1);
171177

172178
sessionFactoryScope.inTransaction(session -> {
@@ -198,7 +204,8 @@ void testSimpleUpdate() {
198204
true,
199205
"str",
200206
BigDecimal.valueOf(10.1),
201-
new ObjectId("000000000000000000000001"));
207+
new ObjectId("000000000000000000000001"),
208+
Instant.parse("2024-01-01T10:00:00Z"));
202209
session.persist(item);
203210
session.flush();
204211
item.primitiveBoolean = false;
@@ -221,7 +228,8 @@ void testSimpleUpdate() {
221228
boxedBoolean: false,
222229
string: "str",
223230
bigDecimal: {$numberDecimal: "10.1"},
224-
objectId: {$oid: "000000000000000000000001"}
231+
objectId: {$oid: "000000000000000000000001"},
232+
instant: {$date: "2024-01-01T10:00:00Z"}
225233
}
226234
""");
227235
}
@@ -243,7 +251,8 @@ void testSimpleUpdateWithNullFieldValues() {
243251
true,
244252
"str",
245253
BigDecimal.valueOf(10.1),
246-
new ObjectId("000000000000000000000001"));
254+
new ObjectId("000000000000000000000001"),
255+
Instant.parse("2024-01-01T10:00:00Z"));
247256
session.persist(item);
248257
session.flush();
249258
item.boxedChar = null;
@@ -254,6 +263,7 @@ void testSimpleUpdateWithNullFieldValues() {
254263
item.string = null;
255264
item.bigDecimal = null;
256265
item.objectId = null;
266+
item.instant = null;
257267
});
258268

259269
assertCollectionContainsExactly(
@@ -272,7 +282,8 @@ void testSimpleUpdateWithNullFieldValues() {
272282
boxedBoolean: null,
273283
string: null,
274284
bigDecimal: null,
275-
objectId: null
285+
objectId: null,
286+
instant: null
276287
}
277288
""");
278289
}
@@ -336,7 +347,8 @@ void testFindByPrimaryKey() {
336347
true,
337348
"str",
338349
BigDecimal.valueOf(10.1),
339-
new ObjectId("000000000000000000000001"));
350+
new ObjectId("000000000000000000000001"),
351+
Instant.parse("2024-01-01T10:00:00Z"));
340352
sessionFactoryScope.inTransaction(session -> session.persist(item));
341353

342354
var loadedItem = sessionFactoryScope.fromTransaction(session -> session.find(Item.class, item.id));
@@ -346,7 +358,21 @@ void testFindByPrimaryKey() {
346358
@Test
347359
void testFindByPrimaryKeyWithNullFieldValues() {
348360
var item = new Item(
349-
1, 'c', 1, Long.MAX_VALUE, Double.MAX_VALUE, true, null, null, null, null, null, null, null, null);
361+
1,
362+
'c',
363+
1,
364+
Long.MAX_VALUE,
365+
Double.MAX_VALUE,
366+
true,
367+
null,
368+
null,
369+
null,
370+
null,
371+
null,
372+
null,
373+
null,
374+
null,
375+
null);
350376
sessionFactoryScope.inTransaction(session -> session.persist(item));
351377

352378
var loadedItem = sessionFactoryScope.fromTransaction(session -> session.find(Item.class, item.id));
@@ -387,7 +413,8 @@ private static void assertCollectionContainsExactly(String documentAsJsonObject)
387413
@ColumnResult(name = "boxedBoolean", type = Boolean.class),
388414
@ColumnResult(name = "string", type = String.class),
389415
@ColumnResult(name = "bigDecimal", type = BigDecimal.class),
390-
@ColumnResult(name = "objectId", type = ObjectId.class)
416+
@ColumnResult(name = "objectId", type = ObjectId.class),
417+
@ColumnResult(name = "instant", type = Instant.class),
391418
}))
392419
@SqlResultSetMapping(
393420
name = MAPPING_FOR_ITEM,
@@ -405,7 +432,8 @@ private static void assertCollectionContainsExactly(String documentAsJsonObject)
405432
@ColumnResult(name = "boxedBoolean"),
406433
@ColumnResult(name = "string"),
407434
@ColumnResult(name = "bigDecimal"),
408-
@ColumnResult(name = "objectId")
435+
@ColumnResult(name = "objectId"),
436+
@ColumnResult(name = "instant")
409437
})
410438
public static class Item {
411439
public static final String COLLECTION_NAME = "items";
@@ -428,6 +456,7 @@ public static class Item {
428456
public String string;
429457
public BigDecimal bigDecimal;
430458
public ObjectId objectId;
459+
public Instant instant;
431460

432461
Item() {}
433462

@@ -445,7 +474,8 @@ public Item(
445474
Boolean boxedBoolean,
446475
String string,
447476
BigDecimal bigDecimal,
448-
ObjectId objectId) {
477+
ObjectId objectId,
478+
Instant instant) {
449479
this.id = id;
450480
this.primitiveChar = primitiveChar;
451481
this.primitiveInt = primitiveInt;
@@ -460,6 +490,7 @@ public Item(
460490
this.string = string;
461491
this.bigDecimal = bigDecimal;
462492
this.objectId = objectId;
493+
this.instant = instant;
463494
}
464495

465496
public static Bson projectAll() {
@@ -477,7 +508,8 @@ public static Bson projectAll() {
477508
"boxedBoolean",
478509
"string",
479510
"bigDecimal",
480-
"objectId"));
511+
"objectId",
512+
"instant"));
481513
}
482514
}
483515

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ void columnWithDollar() {
360360
assertThrows(IdWithDollar.class, '$');
361361
}
362362

363-
private static void assertThrows(final Class<?> annotatedClass, final char unsupportedCharacter) {
363+
private static void assertThrows(Class<?> annotatedClass, char unsupportedCharacter) {
364364
assertThatThrownBy(() -> new MetadataSources()
365365
.addAnnotatedClass(annotatedClass)
366366
.buildMetadata())

0 commit comments

Comments
 (0)