Skip to content

Commit 1e21da1

Browse files
committed
HHH-17520 Schema creation fails with interval second data type on PostgreSQL
1 parent ddb3e57 commit 1e21da1

File tree

6 files changed

+37
-2
lines changed

6 files changed

+37
-2
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CockroachLegacyDialect.java

+6
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,12 @@ public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
11441144
};
11451145
}
11461146

1147+
@Override
1148+
public int getDefaultIntervalSecondScale() {
1149+
// The maximum scale for `interval second` is 6 unfortunately
1150+
return 6;
1151+
}
1152+
11471153
// CockroachDB doesn't support this by default. See sql.multiple_modifications_of_table.enabled
11481154
//
11491155
// @Override

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java

+6
Original file line numberDiff line numberDiff line change
@@ -1460,4 +1460,10 @@ public String addSqlHintOrComment(String sql, QueryOptions queryOptions, boolean
14601460
}
14611461
return sql;
14621462
}
1463+
1464+
@Override
1465+
public int getDefaultIntervalSecondScale() {
1466+
// The maximum scale for `interval second` is 6 unfortunately
1467+
return 6;
1468+
}
14631469
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,11 @@ public String getQueryHintString(String query, List<String> hintList) {
11381138
return new CockroachDialectQueryHints(query, hintList).getQueryHintString();
11391139
}
11401140

1141+
@Override
1142+
public int getDefaultIntervalSecondScale() {
1143+
// The maximum scale for `interval second` is 6 unfortunately
1144+
return 6;
1145+
}
11411146

11421147

11431148
// CockroachDB doesn't support this by default. See sql.multiple_modifications_of_table.enabled

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

+13
Original file line numberDiff line numberDiff line change
@@ -5391,4 +5391,17 @@ public DmlTargetColumnQualifierSupport getDmlTargetColumnQualifierSupport() {
53915391
public FunctionalDependencyAnalysisSupport getFunctionalDependencyAnalysisSupport() {
53925392
return FunctionalDependencyAnalysisSupportImpl.NONE;
53935393
}
5394+
5395+
/**
5396+
* Resolves the default scale for a {@link SqlTypes.INTERVAL_SECOND} type code for the given column
5397+
* <p>
5398+
* Usually 9 (nanosecond) or 6 (microseconds).
5399+
*
5400+
* @return the default scale, in decimal digits,
5401+
* of the fractional seconds field
5402+
*/
5403+
public int getDefaultIntervalSecondScale(){
5404+
// The default scale necessary is 9 i.e. nanosecond resolution
5405+
return 9;
5406+
}
53945407
}

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

+6
Original file line numberDiff line numberDiff line change
@@ -1541,4 +1541,10 @@ public String createMarker(int position, JdbcType jdbcType) {
15411541
return "$" + position;
15421542
}
15431543
}
1544+
1545+
@Override
1546+
public int getDefaultIntervalSecondScale() {
1547+
// The maximum scale for `interval second` is 6 unfortunately
1548+
return 6;
1549+
}
15441550
}

hibernate-core/src/main/java/org/hibernate/type/descriptor/java/DurationJavaType.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ public int getDefaultSqlPrecision(Dialect dialect, JdbcType jdbcType) {
161161
@Override
162162
public int getDefaultSqlScale(Dialect dialect, JdbcType jdbcType) {
163163
if ( jdbcType.getDdlTypeCode() == SqlTypes.INTERVAL_SECOND ) {
164-
// The default scale necessary is 9 i.e. nanosecond resolution
165-
return 9;
164+
return dialect.getDefaultIntervalSecondScale();
166165
}
167166
else {
168167
// For non-interval types, we use the type numeric(21)

0 commit comments

Comments
 (0)