Skip to content

Commit 97fd1e1

Browse files
committed
[#2186] Improve error message when asking for a JDBC connection
1 parent dc72713 commit 97fd1e1

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;
@@ -266,6 +267,9 @@ public interface Log extends BasicLogger {
266267
@Message(id = 83, value = "Unexpected request of a non reactive connection")
267268
HibernateException unexpectedConnectionRequest();
268269

270+
@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")
271+
SQLException notUsingJdbc();
272+
269273
// Same method that exists in CoreMessageLogger
270274
@LogMessage(level = WARN)
271275
@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)