From d6073ec83302d194c652aa205f0ede39ff84e322 Mon Sep 17 00:00:00 2001 From: Valentin Kovalenko Date: Thu, 16 Oct 2025 10:37:24 -0600 Subject: [PATCH] Document default type mapping --- .../hibernate/dialect/MongoDialect.java | 82 ++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/mongodb/hibernate/dialect/MongoDialect.java b/src/main/java/com/mongodb/hibernate/dialect/MongoDialect.java index 12ea1286..e508d380 100644 --- a/src/main/java/com/mongodb/hibernate/dialect/MongoDialect.java +++ b/src/main/java/com/mongodb/hibernate/dialect/MongoDialect.java @@ -30,8 +30,14 @@ import com.mongodb.hibernate.internal.type.ObjectIdJavaType; import com.mongodb.hibernate.internal.type.ObjectIdJdbcType; import com.mongodb.hibernate.jdbc.MongoConnectionProvider; +import java.math.BigDecimal; +import java.time.Instant; +import java.util.Collection; +import org.bson.types.ObjectId; +import org.hibernate.annotations.Struct; import org.hibernate.boot.model.FunctionContributions; import org.hibernate.boot.model.TypeContributions; +import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.DatabaseVersion; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.aggregate.AggregateSupport; @@ -46,6 +52,7 @@ import org.hibernate.sql.model.ValuesAnalysis; import org.hibernate.sql.model.internal.OptionalTableUpdate; import org.hibernate.sql.model.jdbc.OptionalTableUpdateOperation; +import org.hibernate.type.WrapperArrayHandling; import org.hibernate.type.descriptor.sql.internal.DdlTypeImpl; import org.jspecify.annotations.Nullable; @@ -58,6 +65,79 @@ * creating a JDBC adaptor on top of MongoDB Java * Driver. * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Default type mapping
Java typeBSON type
null typeBSON {@code Null}
{@code byte[]}BSON {@code Binary data} with subtype 0
{@code char}, {@link Character}, {@link String}, {@code char[]}BSON {@code String}
{@code int}, {@link Integer}BSON {@code 32-bit integer}
{@code long}, {@link Long}BSON {@code 64-bit integer}
{@code double}, {@link Double}BSON {@code Double}
{@code boolean}, {@link Boolean}BSON {@code Boolean}
{@link BigDecimal}BSON {@code Decimal128}
{@link ObjectId}BSON {@code ObjectId}
{@link Instant}BSON {@code Date}
{@link Struct} aggregate embeddable + * BSON {@code Object} + * + *

Field values are mapped as per this table. + *

+ * array, {@link Collection} (or a subtype supported by Hibernate ORM), + * except for {@code byte[]}, {@code char[]} + * + *

Note that {@link Character}{@code []} requires setting {@value AvailableSettings#WRAPPER_ARRAY_HANDLING} to {@link WrapperArrayHandling#ALLOW}. + *

+ * BSON {@code Array} + * + *

Array elements are mapped as per this table. + *

+ * *

For the documentation on the supported HQL * functions see {@link #initializeFunctionRegistry(FunctionContributions)}. @@ -225,7 +305,7 @@ public boolean supportsStandardArrays() { * *

  • * The second argument must not be an HQL path expression. - * Also, it must be an array and not be a {@link java.util.Collection} when specified as + * Also, it must be an array and not be a {@link Collection} when specified as * {@linkplain org.hibernate.query.SelectionQuery#setParameter(String, Object) query parameter}. *
  • *