Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetching association throws "Unknown parameter type, 116 given" exception #200

Open
delolmo opened this issue Jan 23, 2023 · 6 comments
Open
Labels

Comments

@delolmo
Copy link

delolmo commented Jan 23, 2023

Tbh, I am not 100% sure that this issue lies within this library, within doctrine/orm or within doctrine/dbal. Having said that, let me share my findings on what is happening to me.

The project in question is based on doctrine/orm, which is being tested locally with the pdo_sqlite library. I have two very basic entities with the following mapping:

#[ORM\Entity]
#[ORM\Table(name: 'accounts')]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'type', type: 'string')]
#[ORM\DiscriminatorMap([
    'organization' => Organization::class,
    'user' => User::class,
])]
abstract class Account
{
    public function __construct(
        #[ORM\Id]
        #[ORM\Column(type: 'uuid_binary')]
        private UuidInterface $id,
        #[ORM\Column(type: 'string', unique: true)]
        private string $name,
        #[ORM\Column(type: 'string', unique: true)]
        private string $email,
        #[ORM\Column(type: 'string', enumType: Level::class)]
        private Level $level,
        #[ORM\Column(type: 'datetime_immutable')]
        private DateTimeImmutable $createdAt,
    ) {
    }
#[ORM\Entity]
class User extends Account
{
}
#[ORM\Entity]
class Organization extends Account
{
}

Plus an association class with the following definition:

#[ORM\Entity]
#[ORM\Table(name: 'accounts_members')]
#[ORM\UniqueConstraint(columns: ['organization_id', 'user_id'])]
class Member
{
    final public function __construct(
        #[ORM\Id]
        #[ORM\Column(type: 'uuid_binary')]
        private UuidInterface $id,
        #[ORM\ManyToOne(targetEntity: Organization::class, fetch: 'EAGER')]
        #[ORM\JoinColumn(name: 'organization_id', referencedColumnName: 'id')]
        private Organization $organization,
        #[ORM\ManyToOne(targetEntity: User::class, fetch: 'EAGER')]
        #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id')]
        private User $user,
        #[ORM\Column(type: 'string', enumType: Role::class)]
        private Role $role,
    ) {
    }
}

I believe the entities are self-explanatory, but I will be happy to provide more context if necessary.

That being said, I am running this code inside the controller:

        $entityManager = $this->getEntityManager();

        $repo = $entityManager->getRepository(Member::class);

        $all = $repo->findAll();

After which I am getting the following Exception:

In ExceptionConverter.php line 83:
                                                                                     
  [Doctrine\DBAL\Exception\DriverException]                                          
  An exception occurred while executing a query: Unknown parameter type, 116 given.  
                                                                                     

Exception trace:
  at /.web/model/vendor/doctrine/dbal/src/Driver/API/SQLite/ExceptionConverter.php:83
 Doctrine\DBAL\Driver\API\SQLite\ExceptionConverter->convert() at /.web/model/vendor/doctrine/dbal/src/Connection.php:1907
 Doctrine\DBAL\Connection->handleDriverException() at /.web/model/vendor/doctrine/dbal/src/Connection.php:1850
 Doctrine\DBAL\Connection->convertExceptionDuringQuery() at /.web/model/vendor/doctrine/dbal/src/Connection.php:1069
 Doctrine\DBAL\Connection->executeQuery() at /.web/model/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php:916
 Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadAll() at /.web/model/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:3015
 Doctrine\ORM\UnitOfWork->triggerEagerLoads() at /.web/model/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php:68
 Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator->hydrateAllData() at /.web/model/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php:270
 Doctrine\ORM\Internal\Hydration\AbstractHydrator->hydrateAll() at /.web/model/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php:920
 Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadAll() at /.web/model/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php:225
 Doctrine\ORM\EntityRepository->findBy() at /.web/model/vendor/doctrine/orm/lib/Doctrine/ORM/EntityRepository.php:207
 Doctrine\ORM\EntityRepository->findAll() at /.web/model/src/Handler/ListMembers.php:19
 App\Handler\ListMembers->__invoke() at /.web/model/src/Console/Command/ListMembers.php:27
 App\Controller\ListMembers->execute() at /.web/model/vendor/symfony/console/Command/Command.php:312
 Symfony\Component\Console\Command\Command->run() at /.web/model/vendor/symfony/console/Application.php:1022
 Symfony\Component\Console\Application->doRunCommand() at /.web/model/vendor/symfony/console/Application.php:314
 Symfony\Component\Console\Application->doRun() at /.web/model/vendor/symfony/console/Application.php:168
 Symfony\Component\Console\Application->run() at /.web/model/bin/console:34

After some investigation into the issue, I found out that the misterious unknown parameter 116 is 'created' here:

Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadAll()

Which eventually calls this (the actual line where the 116 is 'added'):

https://github.com/doctrine/orm/blob/2.14.x/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php#L1962

Does anyone have any idea why I am getting this error?

Locked versions of the libraries are:

  • doctrine/orm, 2.14.1
  • ramsey/uuid-doctrine, 2.0.0
  • ramsey/uuid, 4.7.3
@delolmo
Copy link
Author

delolmo commented Jan 26, 2023

I have actually revisited this and it is in fact a bug in the library. Changing every primary key from 'uuid_binary' type to 'uuid' made everything work fine again.

@sakalys
Copy link

sakalys commented Apr 24, 2023

I had the same issue with v2.x. Rolling back to v1 helped. Didn't notice anything in the CHANGELOG.md

@acelot
Copy link

acelot commented Jun 20, 2023

Same here with:

ramsey/uuid: 4.7.4
ramsey/uuid-doctrine: 2.0.0
doctrine/orm: 2.15.2

@acelot
Copy link

acelot commented Jun 20, 2023

It seems it's a bug on ORM side doctrine/orm#7835
TLDR; findBy doesn't accept non-builtin array types

Helped rewriting findBy calls by query builder.

@ramsey
Copy link
Owner

ramsey commented Jun 26, 2023

@acelot Can you provide more details on what you mean by "helped rewriting findBy calls by query builder?"

@vitkutny
Copy link

FYI as its not mentined here. Error "Unknown parameter type, 116 given" is caused by #72 (released in 2.0.0) and already fixed upstream in PR doctrine/dbal#5994 . ArrayParametrType does not support BINARY type right now. After applying patch from PR everything is working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants