Skip to content

Commit 90780a0

Browse files
breglerjbeikov
authored andcommitted
HHH-18946 Fix startup issues with HANA in failover situations
1 parent d4ec549 commit 90780a0

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/HANAServerConfiguration.java

+22-9
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,34 @@ public static HANAServerConfiguration fromDialectResolutionInfo(DialectResolutio
4949
Integer maxLobPrefetchSize = null;
5050
final DatabaseMetaData databaseMetaData = info.getDatabaseMetadata();
5151
if ( databaseMetaData != null ) {
52-
try (final Statement statement = databaseMetaData.getConnection().createStatement()) {
53-
try ( ResultSet rs = statement.executeQuery(
54-
"SELECT TOP 1 VALUE,MAP(LAYER_NAME,'DEFAULT',1,'SYSTEM',2,'DATABASE',3,4) AS LAYER FROM SYS.M_INIFILE_CONTENTS WHERE FILE_NAME='indexserver.ini' AND SECTION='session' AND KEY='max_lob_prefetch_size' ORDER BY LAYER DESC" ) ) {
55-
// This only works if the current user has the privilege INIFILE ADMIN
56-
if ( rs.next() ) {
57-
maxLobPrefetchSize = rs.getInt( 1 );
58-
}
59-
}
52+
int databaseMajorVersion = -1;
53+
try {
54+
databaseMajorVersion = databaseMetaData.getDatabaseMajorVersion();
6055
}
6156
catch (SQLException e) {
6257
// Ignore
6358
LOG.debug(
64-
"An error occurred while trying to determine the value of the HANA parameter indexserver.ini / session / max_lob_prefetch_size.",
59+
"An error occurred while trying to determine the database version.",
6560
e );
6661
}
62+
63+
if (databaseMajorVersion > 0 && databaseMajorVersion < 4) {
64+
try (final Statement statement = databaseMetaData.getConnection().createStatement()) {
65+
try ( ResultSet rs = statement.executeQuery(
66+
"SELECT TOP 1 VALUE,MAP(LAYER_NAME,'DEFAULT',1,'SYSTEM',2,'DATABASE',3,4) AS LAYER FROM SYS.M_CONFIGURATION_PARAMETER_VALUES WHERE FILE_NAME='indexserver.ini' AND SECTION='session' AND KEY='max_lob_prefetch_size' ORDER BY LAYER DESC" ) ) {
67+
// This only works if the current user has the privilege INIFILE ADMIN
68+
if ( rs.next() ) {
69+
maxLobPrefetchSize = rs.getInt( 1 );
70+
}
71+
}
72+
}
73+
catch (SQLException e) {
74+
// Ignore
75+
LOG.debug(
76+
"An error occurred while trying to determine the value of the HANA parameter indexserver.ini / session / max_lob_prefetch_size.",
77+
e );
78+
}
79+
}
6780
}
6881
// default to the dialect-specific configuration settings
6982
if ( maxLobPrefetchSize == null ) {

0 commit comments

Comments
 (0)