Skip to content

Commit f6f00f6

Browse files
committed
[#2186] Improve error message when asking for a JDBC connection
1 parent f2c2222 commit f6f00f6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 5 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,10 @@ public interface Log extends BasicLogger {
266267
@Message(id = 83, value = "Unexpected request of a non reactive connection")
267268
HibernateException unexpectedConnectionRequest();
268269

270+
@LogMessage(level = ERROR)
271+
@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")
272+
SQLException notUsingJdbc();
273+
269274
// Same method that exists in CoreMessageLogger
270275
@LogMessage(level = WARN)
271276
@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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,30 @@
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;
10+
import org.hibernate.reactive.logging.impl.LoggerFactory;
911

12+
import java.lang.invoke.MethodHandles;
1013
import java.sql.Connection;
1114
import java.sql.SQLException;
1215

16+
import static java.lang.invoke.MethodHandles.lookup;
17+
import static org.hibernate.reactive.logging.impl.LoggerFactory.make;
18+
1319
/**
1420
* A dummy Hibernate {@link ConnectionProvider} throws an
1521
* exception if a JDBC connection is requested.
1622
*
1723
* @author Gavin King
1824
*/
1925
public class NoJdbcConnectionProvider implements ConnectionProvider {
26+
private static final Log LOG = make( Log.class, lookup() );
2027

2128
public static final NoJdbcConnectionProvider INSTANCE = new NoJdbcConnectionProvider();
2229

2330
@Override
2431
public Connection getConnection() throws SQLException {
25-
throw new SQLException( "Not using JDBC" );
32+
throw LOG.notUsingJdbc();
2633
}
2734

2835
@Override

0 commit comments

Comments
 (0)