diff --git a/src/integrationTest/resources/hibernate.properties b/src/integrationTest/resources/hibernate.properties index b59c4af4..dfccc938 100644 --- a/src/integrationTest/resources/hibernate.properties +++ b/src/integrationTest/resources/hibernate.properties @@ -1,4 +1,4 @@ -hibernate.dialect=com.mongodb.hibernate.dialect.MongoDialect -hibernate.connection.provider_class=com.mongodb.hibernate.jdbc.MongoConnectionProvider +hibernate.dialect=mongodb +hibernate.connection.provider_class=mongodb-connection-provider jakarta.persistence.jdbc.url=mongodb://localhost/mongo-hibernate-test?directConnection=false hibernate.query.plan_cache_enabled=false #make tests more isolated from each other \ No newline at end of file diff --git a/src/main/java/com/mongodb/hibernate/internal/MongoConstants.java b/src/main/java/com/mongodb/hibernate/internal/MongoConstants.java index 444709cd..f980920a 100644 --- a/src/main/java/com/mongodb/hibernate/internal/MongoConstants.java +++ b/src/main/java/com/mongodb/hibernate/internal/MongoConstants.java @@ -29,4 +29,7 @@ private MongoConstants() {} public static final String MONGO_DBMS_NAME = "MongoDB"; public static final String MONGO_JDBC_DRIVER_NAME = "MongoDB Java Driver JDBC Adapter"; public static final String ID_FIELD_NAME = "_id"; + + public static final String MONGO_DIALECT_SHORT_NAME = "mongodb"; + public static final String MONGO_CONNECTION_PROVIDER_SHORT_NAME = "mongodb-connection-provider"; } diff --git a/src/main/java/com/mongodb/hibernate/internal/extension/MongoStrategyContributor.java b/src/main/java/com/mongodb/hibernate/internal/extension/MongoStrategyContributor.java new file mode 100644 index 00000000..3c1a0d07 --- /dev/null +++ b/src/main/java/com/mongodb/hibernate/internal/extension/MongoStrategyContributor.java @@ -0,0 +1,39 @@ +/* + * Copyright 2025-present MongoDB, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mongodb.hibernate.internal.extension; + +import static com.mongodb.hibernate.internal.MongoConstants.MONGO_CONNECTION_PROVIDER_SHORT_NAME; +import static com.mongodb.hibernate.internal.MongoConstants.MONGO_DIALECT_SHORT_NAME; + +import com.mongodb.hibernate.dialect.MongoDialect; +import com.mongodb.hibernate.jdbc.MongoConnectionProvider; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.boot.registry.selector.spi.StrategySelector; +import org.hibernate.dialect.Dialect; +import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; +import org.hibernate.service.spi.ServiceContributor; + +public final class MongoStrategyContributor implements ServiceContributor { + + @Override + public void contribute(StandardServiceRegistryBuilder serviceRegistryBuilder) { + var selector = serviceRegistryBuilder.getBootstrapServiceRegistry().requireService(StrategySelector.class); + selector.registerStrategyImplementor(Dialect.class, MONGO_DIALECT_SHORT_NAME, MongoDialect.class); + selector.registerStrategyImplementor( + ConnectionProvider.class, MONGO_CONNECTION_PROVIDER_SHORT_NAME, MongoConnectionProvider.class); + } +} diff --git a/src/main/resources/META-INF/services/org.hibernate.service.spi.ServiceContributor b/src/main/resources/META-INF/services/org.hibernate.service.spi.ServiceContributor index 3f3d12fc..bbeae7ce 100644 --- a/src/main/resources/META-INF/services/org.hibernate.service.spi.ServiceContributor +++ b/src/main/resources/META-INF/services/org.hibernate.service.spi.ServiceContributor @@ -1 +1,2 @@ com.mongodb.hibernate.internal.extension.service.StandardServiceRegistryScopedState$ServiceContributor +com.mongodb.hibernate.internal.extension.MongoStrategyContributor \ No newline at end of file diff --git a/src/test/resources/hibernate.properties b/src/test/resources/hibernate.properties index 0fc9e9e2..00cdf5f6 100644 --- a/src/test/resources/hibernate.properties +++ b/src/test/resources/hibernate.properties @@ -1,4 +1,4 @@ -hibernate.dialect=com.mongodb.hibernate.dialect.MongoDialect -hibernate.connection.provider_class=com.mongodb.hibernate.jdbc.MongoConnectionProvider +hibernate.dialect=mongodb +hibernate.connection.provider_class=mongodb-connection-provider hibernate.boot.allow_jdbc_metadata_access=false jakarta.persistence.jdbc.url=mongodb://host/mongo-hibernate-test?directConnection=false