Skip to content

Commit 0a96a58

Browse files
breglerjmbellade
authored andcommitted
HHH-18946 Fix startup issues with HANA in failover situations
(cherry picked from commit 90780a0)
1 parent 31ecca5 commit 0a96a58

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,34 @@ public static HANAServerConfiguration fromDialectResolutionInfo(DialectResolutio
5050
Integer maxLobPrefetchSize = null;
5151
final DatabaseMetaData databaseMetaData = info.getDatabaseMetadata();
5252
if ( databaseMetaData != null ) {
53-
try (final Statement statement = databaseMetaData.getConnection().createStatement()) {
54-
try ( ResultSet rs = statement.executeQuery(
55-
"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" ) ) {
56-
// This only works if the current user has the privilege INIFILE ADMIN
57-
if ( rs.next() ) {
58-
maxLobPrefetchSize = rs.getInt( 1 );
59-
}
60-
}
53+
int databaseMajorVersion = -1;
54+
try {
55+
databaseMajorVersion = databaseMetaData.getDatabaseMajorVersion();
6156
}
6257
catch (SQLException e) {
6358
// Ignore
6459
LOG.debug(
65-
"An error occurred while trying to determine the value of the HANA parameter indexserver.ini / session / max_lob_prefetch_size.",
60+
"An error occurred while trying to determine the database version.",
6661
e );
6762
}
63+
64+
if (databaseMajorVersion > 0 && databaseMajorVersion < 4) {
65+
try (final Statement statement = databaseMetaData.getConnection().createStatement()) {
66+
try ( ResultSet rs = statement.executeQuery(
67+
"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" ) ) {
68+
// This only works if the current user has the privilege INIFILE ADMIN
69+
if ( rs.next() ) {
70+
maxLobPrefetchSize = rs.getInt( 1 );
71+
}
72+
}
73+
}
74+
catch (SQLException e) {
75+
// Ignore
76+
LOG.debug(
77+
"An error occurred while trying to determine the value of the HANA parameter indexserver.ini / session / max_lob_prefetch_size.",
78+
e );
79+
}
80+
}
6881
}
6982
// default to the dialect-specific configuration settings
7083
if ( maxLobPrefetchSize == null ) {

0 commit comments

Comments
 (0)