When starting a session with an empty hibernate config ([test project|https://github.com/rzymek/hibernate-minimal-project ] ) ) :
{code:java} final StandardServiceRegistry registry = new StandardServiceRegistryBuilder() .build(); SessionFactory sessionFactory = new MetadataSources(registry) .buildMetadata() .buildSessionFactory(); try (Session session = sessionFactory.openSession()) { session.beginTransaction(); session.getTransaction().commit(); } {code}
The error that gets propagated to the user contains a cryptic message about a missing dialect:
{noformat} Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100) at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137) at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259) ... 18 more {noformat}
[(Complete output)|https://github.com/rzymek/hibernate-minimal-project/blob/5.2.8/output.txt]
A more appropriate error should inform about the main issue here - no available connection.
I propose to change the dialect detection procedure to return a default dialect (aka `new Dialect() {}`) on failure and moving on. The exception that gets propagated to the user becomes:
{noformat} Exception in thread "main" java.lang.UnsupportedOperationException: The application must supply JDBC connections at org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl.getConnection(UserSuppliedConnectionProviderImpl.java:44) at org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:35) at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:99) at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:129) .... {noformat} [(Complete output)|https://github.com/rzymek/hibernate-minimal-project/blob/master/output.txt]
_Instead of returning an anonymous instance of Dialect, a new `DefaultDialect` class might be a better choice._ |
|