HHH-16444 When logging the selected dialect, log the db version too

The db version used by the dialect makes a huge different on the
sql queries used.

The log before this commit:
```
INFO SQL dialect [vert.x-worker-thread-0] HHH000400: Using dialect: org.hibernate.dialect.MariaDBDialect
```

The log after this commit:
```
INFO SQL dialect [vert.x-worker-thread-0] HHH000400: Using dialect: org.hibernate.dialect.MariaDBDialect, version: 10.11
```

I've also updated the HANADialectTestCase because now the error message
contains the db version
This commit is contained in:
Davide D'Alto 2023-04-06 11:19:56 +01:00 committed by Davide D'Alto
parent 4eef64f81e
commit 1de4a76008
3 changed files with 28 additions and 14 deletions

View File

@ -1528,7 +1528,7 @@ public abstract class Dialect implements ConversionContext, TypeContributor, Fun
@Override
public String toString() {
return getClass().getName();
return getClass().getName() + ", version: " + getVersion();
}

View File

@ -84,4 +84,21 @@ public class SimpleDatabaseVersion implements DatabaseVersion {
public int getMicro() {
return micro;
}
@Override
public String toString() {
StringBuilder version = new StringBuilder();
if ( major != NO_VERSION ) {
version.append( major );
}
if ( minor != NO_VERSION ) {
version.append( "." );
version.append( minor );
if ( micro > 0 ) {
version.append( "." );
version.append( micro );
}
}
return version.toString();
}
}

View File

@ -29,11 +29,10 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import org.hamcrest.MatcherAssert;
import static org.hamcrest.core.Is.is;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class HANADialectTestCase extends BaseUnitTestCase {
@Test
@ -42,20 +41,18 @@ public class HANADialectTestCase extends BaseUnitTestCase {
() -> new StandardServiceRegistryBuilder()
.applySetting( AvailableSettings.DIALECT, HANAColumnStoreDialect.class )
.build(),
(registryScope) -> {
registryScope -> {
final StandardServiceRegistry registry = registryScope.getRegistry();
final MetadataSources metadataSources = new MetadataSources( registry );
metadataSources.addAnnotatedClass( EntityWithIdentity.class );
try ( SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) metadataSources.buildMetadata().buildSessionFactory() ) {
fail( "Should have thrown MappingException!" );
}
catch (MappingException e) {
MatcherAssert.assertThat(
e.getMessage(),
is( "The INSERT statement for table [EntityWithIdentity] contains no column, and this is not supported by [" + HANAColumnStoreDialect.class.getName() + "]" )
);
}
String errorMessage = assertThrows( MappingException.class, () -> {
try ( SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) metadataSources.buildMetadata().buildSessionFactory() ) {
// Nothing to do, we expect an exception
}
} ).getMessage();
assertThat( errorMessage )
.matches( "The INSERT statement for table \\[EntityWithIdentity\\] contains no column, and this is not supported by \\[" + HANAColumnStoreDialect.class.getName() + ", version: [\\d\\.]+\\]" );
}
);
}