Second level cache does not support scalar results. #7188

Open
opened 2026-01-22 15:46:22 +01:00 by admin · 2 comments
Owner

Originally created by @konmedia-devops on GitHub (Jul 27, 2023).

I'm not sure if I have a different problem than discussed in #6627 or if it's a new topic. If I use the Querybuilder to create a query that adds the selects individually (because functions still have to be used in the select > AES_DECRYPT), I get the error message mentioned.
I map the content as an object directly to the entity with \Doctrine\ORM\AbstractQuery::HYDRATE_OBJECT

This only seems to work if you do the following:

$className = \Brandbox\Framework\Brandbox\Administrator\Lib\Entity\Administrator::class;
$alias = 'administrator';

$qb = new \Doctrine\ORM\QueryBuilder();
$qb
  ->select($alias)
  ->from($className, $alias)
  ->getQuery()
  ->getResult(\Doctrine\ORM\AbstractQuery::HYDRATE_OBJECT)
;

It doesn't work when I do it like this:

$qb = new \Doctrine\ORM\QueryBuilder();

$repository = $this
    ->entityInstance
    ->getRootRepository()
;
$columns = $repository
    ->getMetadata()
    ->getFieldNames()
;

foreach ($columns as $column) {
    $columnName = $this->alias . '.' . $column;

    if ($this->isEncryptedColumn($column)) {
        $select= 'AES_DECRYPT(' . $columnName . ', "' . $cryptoKey . '") USING UTF8 AS ' . $column;
    } else {
        $select = $columnName . ' AS ' . $column;
    }

    $qb->addSelect($select);
}

$qb
  ->from($className, $alias)
  ->getQuery()
  ->getResult(\Doctrine\ORM\AbstractQuery::HYDRATE_OBJECT)
;

The same structure (also internally) suddenly brings an error:
Second level cache does not support scalar results.

Do you have a tip what's wrong here? Thank you.

Originally created by @konmedia-devops on GitHub (Jul 27, 2023). I'm not sure if I have a different problem than discussed in #6627 or if it's a new topic. If I use the Querybuilder to create a query that adds the selects individually (because functions still have to be used in the select > AES_DECRYPT), I get the error message mentioned. I map the content as an object directly to the entity with \Doctrine\ORM\AbstractQuery::HYDRATE_OBJECT This only seems to work if you do the following: ``` $className = \Brandbox\Framework\Brandbox\Administrator\Lib\Entity\Administrator::class; $alias = 'administrator'; $qb = new \Doctrine\ORM\QueryBuilder(); $qb ->select($alias) ->from($className, $alias) ->getQuery() ->getResult(\Doctrine\ORM\AbstractQuery::HYDRATE_OBJECT) ; ``` It doesn't work when I do it like this: ``` $qb = new \Doctrine\ORM\QueryBuilder(); $repository = $this ->entityInstance ->getRootRepository() ; $columns = $repository ->getMetadata() ->getFieldNames() ; foreach ($columns as $column) { $columnName = $this->alias . '.' . $column; if ($this->isEncryptedColumn($column)) { $select= 'AES_DECRYPT(' . $columnName . ', "' . $cryptoKey . '") USING UTF8 AS ' . $column; } else { $select = $columnName . ' AS ' . $column; } $qb->addSelect($select); } $qb ->from($className, $alias) ->getQuery() ->getResult(\Doctrine\ORM\AbstractQuery::HYDRATE_OBJECT) ; ``` The same structure (also internally) suddenly brings an error: Second level cache does not support scalar results. Do you have a tip what's wrong here? Thank you.
admin added the Bug label 2026-01-22 15:46:22 +01:00
Author
Owner

@derrabus commented on GitHub (Jul 27, 2023):

I don't have a solution to your cache problem, but looking at your code I wonder if you really need that custom query if what you actually want is to hydrate an entity. Shouldn't it be possible to achieve the same thing with a custom DBAL type for your encrypted columns?

@derrabus commented on GitHub (Jul 27, 2023): I don't have a solution to your cache problem, but looking at your code I wonder if you really need that custom query if what you actually want is to hydrate an entity. Shouldn't it be possible to achieve the same thing with a custom DBAL type for your encrypted columns?
Author
Owner

@konmedia-devops commented on GitHub (Jul 28, 2023):

Thank you for your reply.

We had a solution with Types a few years ago. This works conditionally, depending on whether a further transformation of the data is added. We already use the types for other transformation aspects and would now have to create combinations associated with the encryption. I will validate that again. Anyway, thanks for the hint.

However, I now notice that when using the second code block without 2nd-lc, the hydration no longer works. In some cases, I no longer get an object, but an array. Is that an indication of the underlying problem?

I would like to understand why my code behaves this way. I've already debugged and can't get to the point that ensures that scalars are used. Can you name code reference? Just for understanding...

@konmedia-devops commented on GitHub (Jul 28, 2023): Thank you for your reply. We had a solution with Types a few years ago. This works conditionally, depending on whether a further transformation of the data is added. We already use the types for other transformation aspects and would now have to create combinations associated with the encryption. I will validate that again. Anyway, thanks for the hint. However, I now notice that when using the second code block without 2nd-lc, the hydration no longer works. In some cases, I no longer get an object, but an array. Is that an indication of the underlying problem? I would like to understand why my code behaves this way. I've already debugged and can't get to the point that ensures that scalars are used. Can you name code reference? Just for understanding...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7188