diff --git a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java index 39dd8d9c05..acfaa3dc81 100644 --- a/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java +++ b/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java @@ -58,6 +58,7 @@ import org.hibernate.metamodel.spi.RuntimeModelCreationContext; import org.hibernate.procedure.internal.PostgreSQLCallableStatementSupport; import org.hibernate.procedure.spi.CallableStatementSupport; import org.hibernate.query.SemanticException; +import org.hibernate.query.spi.QueryOptions; import org.hibernate.query.sqm.FetchClauseType; import org.hibernate.query.sqm.IntervalType; import org.hibernate.query.sqm.TemporalUnit; @@ -1442,4 +1443,21 @@ public class PostgreSQLLegacyDialect extends Dialect { public int rowIdSqlType() { return OTHER; } + + @Override + public String getQueryHintString(String sql, String hints) { + return "/*+ " + hints + " */ " + sql; + } + + @Override + public String addSqlHintOrComment(String sql, QueryOptions queryOptions, boolean commentsEnabled) { + // PostgreSQL's extension pg_hint_plan needs the hint to be the first comment + if ( commentsEnabled && queryOptions.getComment() != null ) { + sql = prependComment( sql, queryOptions.getComment() ); + } + if ( queryOptions.getDatabaseHints() != null && queryOptions.getDatabaseHints().size() > 0 ) { + sql = getQueryHintString( sql, queryOptions.getDatabaseHints() ); + } + return sql; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java index e0f984e246..10b4ae0a5a 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java @@ -56,6 +56,7 @@ import org.hibernate.persister.entity.mutation.EntityMutationTarget; import org.hibernate.procedure.internal.PostgreSQLCallableStatementSupport; import org.hibernate.procedure.spi.CallableStatementSupport; import org.hibernate.query.SemanticException; +import org.hibernate.query.spi.QueryOptions; import org.hibernate.query.sqm.FetchClauseType; import org.hibernate.query.sqm.IntervalType; import org.hibernate.query.sqm.TemporalUnit; @@ -1476,6 +1477,22 @@ public class PostgreSQLDialect extends Dialect { return OTHER; } + @Override + public String getQueryHintString(String sql, String hints) { + return "/*+ " + hints + " */ " + sql; + } + + @Override + public String addSqlHintOrComment(String sql, QueryOptions queryOptions, boolean commentsEnabled) { + // PostgreSQL's extension pg_hint_plan needs the hint to be the first comment + if ( commentsEnabled && queryOptions.getComment() != null ) { + sql = prependComment( sql, queryOptions.getComment() ); + } + if ( queryOptions.getDatabaseHints() != null && queryOptions.getDatabaseHints().size() > 0 ) { + sql = getQueryHintString( sql, queryOptions.getDatabaseHints() ); + } + return sql; + } @FunctionalInterface private interface OptionalTableUpdateStrategy {