Well, this is my first time doing this, I’ve only been programming for a few months, so I’ll explain the workflow where the “error” occurs.
Everything starts in the class “public class JdbcEnvironmentInitiator implements StandardServiceInitiator” of the package:
“org.hibernate.engine.jdbc.env.internal”
in the method:
@Override
public JdbcEnvironment initiateService(Map<String, Object> configurationValues, ServiceRegistryImplementor registry)
Here a lot of information is loaded from the “environment” (hence my question in what context do you get the data from the database from the environment, because I understand that it is provided by the driver, and cannot come from the configuration values, which is a HashMap that brings information from the environment and some Hibernate configurations)
Then we move on to the section of loading the jdbcenviroment by 3 possible means: with accessible metadata, with explicit configurations and the default values.
My situation is metadata, because my drive with my database provides it and it is accessible
The getJdbcEnvironmentUsingJdbcMetadata method does several things, it builds the connection, the service, a temporary session, and then starts an executor that activates Hikari to get the connections to the DB.
In the following image you can see that it loads all the metadata provided by the connection to create a “dialectResolutionInfo”
Then a new JdbcEnvironmentImpl object is created using the above data, I won’t go into details, just that this object builds the Dialect, and because IBM is not among the standards, the construction of the dialect is somewhat abstract, and the construction of the JdbcEnvironmentImpl object only matters that it has metadata and dialect.
Now returning to the main code segment is where the problem occurs, the record is provided which in this case does not have the DB data, and the dialect is provided, which does not have all the DB data that the record requests, it only has the databaseversion object, metadata has jdbcurl, jdbcdriver, and connection which is not being returned by JdbcEnvironmentImpl has the value of whether autocommit is enabled and the default isolation level, the datasource which is located within the configurationvalues hashmap under the key “hibernate.connection.datasource” has the pool sizes (although there is only the max one)
Here a validation is done using the registry to check the case it is in (both lead to the same final constructor), and the function is called and the dialect is provided, I will show when the first if is fulfilled
Call this function of type default in the interface “public interface ConnectionProvider extends Service, Wrapped” found in the package: “org.hibernate.engine.jdbc.connections.spi” and build a new object DatabaseConnectionInfoImpl
Now we have reached the class: “public class DatabaseConnectionInfoImpl implements DatabaseConnectionInfo” in package: “org.hibernate.engine.jdbc.connections.internal”
Here you can see that all values are loaded with null except the database version, this calls another constructor within the same class which loads these values as they are
After returning the object completely, it reaches this line and its method is called to create the String that will be loaded into the Log
In this method, if it detects that the object is empty, it loads the default value that is in the same class that looks like this → public static final String DEFAULT = “undefined/unknown”
resulting in the Log that does not show the complete data
What occurs to me is that in the process of creating the dialectResolutioninfo, and jdbcenvironmentimpl, since in this part the metadata and connection are obtained, in the configuration values the keys and values corresponding to the url, driver, autocommit, Insulationlevel and the poolsize (that the datasource is within the hashmap at that moment), then 2 values could be returned, the new JdbcEnvironmentImpl and the Configurationvalue (I don’t know if by reference the Configurationvalue is updated in the context of the main method, if so, it is not necessary to return it)
and that this method is able to receive the configuration values as settings
The getDatabaseConnectionInfo of both objects also requires receiving the hashmap as settings
and instead of calling the constructor that only receives dialect, call the other one
This
and there they check the functions, what the keys that this already implemented code receives are called, and that would load the information correctly and return the object, and when obtaining its String version everything would be displayed correctly.
I don’t know if I’m not taking something into account, but with the code I saw, and in the use case where information is loaded through the metadata that could not be obtained previously by the configurationvalues that reach this function, in that case to avoid this you can use computeIfAbsent to add the values. I hope my answer is useful.