From 044d91411f5a303b8477246d41581c7447dfc9c9 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Fri, 18 Oct 2024 13:06:36 +0200 Subject: [PATCH] slight improvements to error messages when driver class missing --- .../internal/DriverManagerConnectionCreator.java | 2 +- .../java/org/hibernate/internal/CoreMessageLogger.java | 2 +- .../org/hibernate/internal/log/ConnectionInfoLogger.java | 7 ++++++- .../orm/test/idgen/userdefined/SimpleBeanContainer.java | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionCreator.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionCreator.java index bbb3e14724..872c0b1b83 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionCreator.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionCreator.java @@ -34,7 +34,7 @@ public class DriverManagerConnectionCreator extends BasicConnectionCreator { return DriverManager.getConnection( url, connectionProps ); } catch (SQLException e) { - throw convertSqlException( "Error calling DriverManager.getConnection()", e ); + throw convertSqlException( "Error calling JDBC 'DriverManager.getConnection()'", e ); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java index 32036aa50b..963fe96ae4 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java @@ -517,7 +517,7 @@ public interface CoreMessageLogger extends BasicLogger { void unableToObtainConnectionMetadata(SQLException error); @LogMessage(level = WARN) - @Message(value = "Could not obtain connection to query metadata", id = 342) + @Message(value = "Could not obtain connection to query JDBC database metadata", id = 342) void unableToObtainConnectionToQueryMetadata(@Cause Exception e); @LogMessage(level = ERROR) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/log/ConnectionInfoLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/log/ConnectionInfoLogger.java index 642f829b3e..2c97209c4f 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/log/ConnectionInfoLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/log/ConnectionInfoLogger.java @@ -7,6 +7,7 @@ package org.hibernate.internal.log; import java.lang.invoke.MethodHandles; import java.sql.SQLException; +import org.hibernate.cfg.JdbcSettings; import org.jboss.logging.BasicLogger; import org.jboss.logging.Logger; import org.jboss.logging.annotations.Cause; @@ -45,7 +46,11 @@ public interface ConnectionInfoLogger extends BasicLogger { void logConnectionInfoDetails(String databaseConnectionInfo); @LogMessage(level = WARN) - @Message(id = 10001006, value = "No JDBC Driver class was specified by property `jakarta.persistence.jdbc.driver`, `hibernate.driver` or `javax.persistence.jdbc.driver`") + @Message(id = 10001006, + value = "No JDBC Driver class was specified by property '" + + JdbcSettings.JAKARTA_JDBC_DRIVER + "', '" + + JdbcSettings.JPA_JDBC_DRIVER + "', or '" + + JdbcSettings.DRIVER + "'") void jdbcDriverNotSpecified(); @LogMessage(level = DEBUG) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/idgen/userdefined/SimpleBeanContainer.java b/hibernate-core/src/test/java/org/hibernate/orm/test/idgen/userdefined/SimpleBeanContainer.java index bc7f895e66..a25d524fa6 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/idgen/userdefined/SimpleBeanContainer.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/idgen/userdefined/SimpleBeanContainer.java @@ -13,12 +13,12 @@ import org.hibernate.resource.beans.spi.BeanInstanceProducer; /** * @author Yanming Zhou */ -@SuppressWarnings("unchecked") public class SimpleBeanContainer implements BeanContainer { public static final long INITIAL_VALUE = 23L; @Override + @SuppressWarnings("unchecked") public ContainedBean getBean( Class beanType, LifecycleOptions lifecycleOptions,