defaultQueryHints is not applied doctrine generated queries #6146

Closed
opened 2026-01-22 15:27:40 +01:00 by admin · 2 comments
Owner

Originally created by @tinntsea on GitHub (Dec 26, 2018).

Originally assigned to: @tinntsea on GitHub.

Bug Report

I'm using symfony 3, postgres, and doctrine 2.6.2.
I wanted the application to read from master db in some cases to prevent replication lag issue.

So I used setDefaultQueryHints function in order to append /NO LOAD BALANCE/ comment as prefix of every select query.

$emConfiguration->setDefaultQueryHints(array_merge(
                [
                    Query::HINT_CUSTOM_OUTPUT_WALKER => SqlCommentWalker::class,
                    SqlCommentWalker::POSITION => SqlCommentWalker::POSITION_PREPEND,
                    SqlCommentWalker::COMMENT => SqlCommentWalker::COMMENT_READ_MASTER,
                ],
                $emConfiguration->getDefaultQueryHints()
))

The thing is it is not applied to doctrine generated queries

# Doctrine\ORM\Configuration

    /**
     * Sets array of query hints, which will be applied to every query in application
     *
     * @since 2.5
     *
     * @param array $defaultQueryHints
     */
    public function setDefaultQueryHints(array $defaultQueryHints)
    {
        $this->_attributes['defaultQueryHints'] = $defaultQueryHints;
    }

Originally created by @tinntsea on GitHub (Dec 26, 2018). Originally assigned to: @tinntsea on GitHub. ### Bug Report I'm using symfony 3, postgres, and doctrine 2.6.2. I wanted the application to read from master db in some cases to prevent replication lag issue. So I used setDefaultQueryHints function in order to append /*NO LOAD BALANCE*/ comment as prefix of every select query. ``` $emConfiguration->setDefaultQueryHints(array_merge( [ Query::HINT_CUSTOM_OUTPUT_WALKER => SqlCommentWalker::class, SqlCommentWalker::POSITION => SqlCommentWalker::POSITION_PREPEND, SqlCommentWalker::COMMENT => SqlCommentWalker::COMMENT_READ_MASTER, ], $emConfiguration->getDefaultQueryHints() )) ``` The thing is it is not applied to doctrine generated queries ``` # Doctrine\ORM\Configuration /** * Sets array of query hints, which will be applied to every query in application * * @since 2.5 * * @param array $defaultQueryHints */ public function setDefaultQueryHints(array $defaultQueryHints) { $this->_attributes['defaultQueryHints'] = $defaultQueryHints; } ```
admin added the BugMissing Tests labels 2026-01-22 15:27:40 +01:00
admin closed this issue 2026-01-22 15:27:41 +01:00
Author
Owner

@Ocramius commented on GitHub (Dec 27, 2018):

it is not applied to doctrine generated queries

Could you please make an example or failing test case?

@Ocramius commented on GitHub (Dec 27, 2018): > it is not applied to doctrine generated queries Could you please make an example or failing test case?
Author
Owner

@beberlei commented on GitHub (Dec 6, 2020):

Doctrine does not use DQL internally, as such the query hints are not applied.

@beberlei commented on GitHub (Dec 6, 2020): Doctrine does not use DQL internally, as such the query hints are not applied.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6146