Skip to content

Commit dfb9eea

Browse files
committed
[#2186] Improve error message when asking for a JDBC connection
1 parent 2aba8d6 commit dfb9eea

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/logging/impl/Log.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88

99

10+
import java.sql.SQLException;
1011
import java.sql.SQLWarning;
1112

1213
import jakarta.persistence.PersistenceException;
@@ -258,6 +259,9 @@ public interface Log extends BasicLogger {
258259
@Message(id = 80, value = "No results were returned by the query (you can try running it with '.executeUpdate()'): %1$s")
259260
HibernateException noResultException(String sql);
260261

262+
@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")
263+
SQLException notUsingJdbc();
264+
261265
// Same method that exists in CoreMessageLogger
262266
@LogMessage(level = WARN)
263267
@Message(id = 104, value = "firstResult/maxResults specified with collection fetch; applying in memory!" )

hibernate-reactive-core/src/main/java/org/hibernate/reactive/provider/service/NoJdbcConnectionProvider.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,28 @@
66
package org.hibernate.reactive.provider.service;
77

88
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
9+
import org.hibernate.reactive.logging.impl.Log;
910

1011
import java.sql.Connection;
1112
import java.sql.SQLException;
1213

14+
import static java.lang.invoke.MethodHandles.lookup;
15+
import static org.hibernate.reactive.logging.impl.LoggerFactory.make;
16+
1317
/**
1418
* A dummy Hibernate {@link ConnectionProvider} throws an
1519
* exception if a JDBC connection is requested.
1620
*
1721
* @author Gavin King
1822
*/
1923
public class NoJdbcConnectionProvider implements ConnectionProvider {
24+
private static final Log LOG = make( Log.class, lookup() );
2025

2126
public static final NoJdbcConnectionProvider INSTANCE = new NoJdbcConnectionProvider();
2227

2328
@Override
2429
public Connection getConnection() throws SQLException {
25-
throw new SQLException( "Not using JDBC" );
30+
throw LOG.notUsingJdbc();
2631
}
2732

2833
@Override

0 commit comments

Comments
 (0)