diff --git a/src/integrationTest/resources/hibernate.properties b/src/integrationTest/resources/hibernate.properties index 162cadb2..7c388aed 100644 --- a/src/integrationTest/resources/hibernate.properties +++ b/src/integrationTest/resources/hibernate.properties @@ -1,3 +1,3 @@ jakarta.persistence.jdbc.url=mongodb://localhost/mongo-hibernate-test?directConnection=false -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 diff --git a/src/main/java/com/mongodb/hibernate/dialect/MongoStragetyContributor.java b/src/main/java/com/mongodb/hibernate/dialect/MongoStragetyContributor.java new file mode 100644 index 00000000..b7fd1879 --- /dev/null +++ b/src/main/java/com/mongodb/hibernate/dialect/MongoStragetyContributor.java @@ -0,0 +1,37 @@ +/* + * 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.dialect; + +import static com.mongodb.hibernate.internal.MongoAssertions.assertNotNull; + +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 class MongoStragetyContributor implements ServiceContributor { + @Override + public void contribute(StandardServiceRegistryBuilder serviceRegistryBuilder) { + var selector = assertNotNull( + serviceRegistryBuilder.getBootstrapServiceRegistry().getService(StrategySelector.class)); + selector.registerStrategyImplementor(Dialect.class, "mongodb", MongoDialect.class); + selector.registerStrategyImplementor( + ConnectionProvider.class, "mongodb-connection-provider", 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 new file mode 100644 index 00000000..6c30649d --- /dev/null +++ b/src/main/resources/META-INF/services/org.hibernate.service.spi.ServiceContributor @@ -0,0 +1 @@ +com.mongodb.hibernate.dialect.MongoStragetyContributor \ No newline at end of file diff --git a/src/test/resources/hibernate.properties b/src/test/resources/hibernate.properties index 98d656f9..8df75a9f 100644 --- a/src/test/resources/hibernate.properties +++ b/src/test/resources/hibernate.properties @@ -1,4 +1,4 @@ jakarta.persistence.jdbc.url=mongodb://localhost/mongo-hibernate-test?directConnection=false -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