Skip to content

[3.0] Improve error message when asking for a JDBC connection #2294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@



import java.sql.SQLException;
import java.sql.SQLWarning;

import jakarta.persistence.PersistenceException;
Expand Down Expand Up @@ -266,6 +267,9 @@ public interface Log extends BasicLogger {
@Message(id = 83, value = "Unexpected request of a non reactive connection")
HibernateException unexpectedConnectionRequest();

@Message(id = 84, value = "The application requested a JDBC connection, but Hibernate Reactive doesn't use JDBC. This could be caused by a bug or the use of an unsupported feature in Hibernate Reactive")
SQLException notUsingJdbc();

// Same method that exists in CoreMessageLogger
@LogMessage(level = WARN)
@Message(id = 104, value = "firstResult/maxResults specified with collection fetch; applying in memory!" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,28 @@
package org.hibernate.reactive.provider.service;

import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.reactive.logging.impl.Log;

import java.sql.Connection;
import java.sql.SQLException;

import static java.lang.invoke.MethodHandles.lookup;
import static org.hibernate.reactive.logging.impl.LoggerFactory.make;

/**
* A dummy Hibernate {@link ConnectionProvider} throws an
* exception if a JDBC connection is requested.
*
* @author Gavin King
*/
public class NoJdbcConnectionProvider implements ConnectionProvider {
private static final Log LOG = make( Log.class, lookup() );

public static final NoJdbcConnectionProvider INSTANCE = new NoJdbcConnectionProvider();

@Override
public Connection getConnection() throws SQLException {
throw new SQLException( "Not using JDBC" );
throw LOG.notUsingJdbc();
}

@Override
Expand Down
Loading