Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
-
My UUID config is as follows: // config/packages/uid.yamlframework:uid:default_uuid_version:7time_based_uuid_version:7
My entity has: #[ORM\Id] #[ORM\Column(type: UuidType::NAME, unique:true)] #[ORM\GeneratedValue(strategy:'CUSTOM')] #[ORM\CustomIdGenerator(class:'doctrine.uuid_generator')]private ?Uuid$id; The auto-generated entity ID UUIDs are V6, not V7. If I inspect any of the UUID primary keys in the database with:
It outputs:
QuestionHow does one configure the Doctrine Bridge UUID generator to generate V7 UUIDs? |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 3 comments 8 replies
-
I don’t see how it could happen 🤔 could you provide a reproducer? BTW UUID can be generated client-side, which avoids declaring your identifier nullable, which is better. |
BetaWas this translation helpful?Give feedback.
All reactions
-
It has something to do withthis UuidFactory component: namespaceSymfony\Component\Uid\Factory;useSymfony\Component\Uid\Uuid;useSymfony\Component\Uid\UuidV1;useSymfony\Component\Uid\UuidV4;useSymfony\Component\Uid\UuidV5;useSymfony\Component\Uid\UuidV6;class UuidFactory{privatestring$defaultClass;privatestring$timeBasedClass;privatestring$nameBasedClass;privatestring$randomBasedClass;private ?Uuid$timeBasedNode;private ?Uuid$nameBasedNamespace;publicfunction__construct(string|int$defaultClass = UuidV6::class,string|int$timeBasedClass = UuidV6::class,string|int$nameBasedClass = UuidV5::class,string|int$randomBasedClass = UuidV4::class,Uuid|string$timeBasedNode =null,Uuid|string$nameBasedNamespace =null) {if (null !==$timeBasedNode && !$timeBasedNodeinstanceof Uuid) {$timeBasedNode = Uuid::fromString($timeBasedNode); }if (null !==$nameBasedNamespace) {$nameBasedNamespace =$this->getNamespace($nameBasedNamespace); }$this->defaultClass =is_numeric($defaultClass) ? Uuid::class.'V'.$defaultClass :$defaultClass;$this->timeBasedClass =is_numeric($timeBasedClass) ? Uuid::class.'V'.$timeBasedClass :$timeBasedClass;$this->nameBasedClass =is_numeric($nameBasedClass) ? Uuid::class.'V'.$nameBasedClass :$nameBasedClass;$this->randomBasedClass =is_numeric($randomBasedClass) ? Uuid::class.'V'.$randomBasedClass :$randomBasedClass;$this->timeBasedNode =$timeBasedNode;$this->nameBasedNamespace =$nameBasedNamespace; }publicfunctioncreate():Uuid {$class =$this->defaultClass;returnnew$class(); } TheUuidGenerator class is instantiated with namespaceSymfony\Bridge\Doctrine\IdGenerator;useDoctrine\ORM\EntityManager;useDoctrine\ORM\EntityManagerInterface;useDoctrine\ORM\Id\AbstractIdGenerator;useSymfony\Component\Uid\Factory\NameBasedUuidFactory;useSymfony\Component\Uid\Factory\RandomBasedUuidFactory;useSymfony\Component\Uid\Factory\TimeBasedUuidFactory;useSymfony\Component\Uid\Factory\UuidFactory;useSymfony\Component\Uid\Uuid;finalclass UuidGeneratorextends AbstractIdGenerator{privatereadonlyUuidFactory$protoFactory;privateUuidFactory|NameBasedUuidFactory|RandomBasedUuidFactory|TimeBasedUuidFactory$factory;private ?string$entityGetter =null;publicfunction__construct(UuidFactory$factory =null) {$this->protoFactory =$this->factory =$factory ??newUuidFactory(); } When I dump the $factory parameter it is NULL: publicfunction__construct(UuidFactory$factory =null) {dump($factory);$this->protoFactory =$this->factory =$factory ??newUuidFactory(); } |
BetaWas this translation helpful?Give feedback.
All reactions
-
The work-around is to not use the auto-generation in the entity: #[ORM\Id] #[ORM\Column(type: UuidType::NAME, unique:true)]private ?Uuid$id =null;publicfunction__construct() {$this->id = Uuid::v7(); } It works fine with no problems. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
OK, but that has no bearing on the issue. |
BetaWas this translation helpful?Give feedback.
All reactions
-
I think this workaround is no longer needed Symfony fixed it and now generates Uuids v7 |
BetaWas this translation helpful?Give feedback.
All reactions
-
Nothing is fixed for me, still generating v6 by default. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
I tried to created a own declare(strict_types=1);namespaceApp\Entity\Doctrine;useDoctrine\ORM\EntityManagerInterface;useDoctrine\ORM\Id\AbstractIdGenerator;useSymfony\Component\Uid\Uuid;useSymfony\Component\Uid\UuidV7;class UuidV7Generatorextends AbstractIdGenerator{publicfunctiongenerateId(EntityManagerInterface$em,$entity):UuidV7 {return Uuid::v7(); }} #[ORM\Id] #[ORM\Column(type: UuidType::NAME, unique:true)] #[ORM\GeneratedValue(strategy:'CUSTOM')] #[ORM\CustomIdGenerator(class: UuidV7Generator::class)]publicreadonly Uuid$id; With this Workaround a UuidV7 was saved in the Database. |
BetaWas this translation helpful?Give feedback.
All reactions
👍 2
-
Hi everyone, Same problem on our project, even with redeclaring manually uuid.factory:class:'Symfony\Component\Uid\Factory\UuidFactory'arguments:$defaultClass:7$timeBasedClass:7doctrine.uuid_generator:class:'Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator'arguments:$factory:'@uuid.factory' |
BetaWas this translation helpful?Give feedback.
All reactions
👍 1
-
Seeing that this impacts many people I spent some time investigating what’s going on. First, using the DoctrineBridge
If you don’t care about those issues, you need to register So, for the final answer: services:Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator:~ |
BetaWas this translation helpful?Give feedback.
All reactions
🎉 1
-
Many thanks for the explanations 🙂 |
BetaWas this translation helpful?Give feedback.