-
I normally use DI for everything, but I kept getting exceptions with duplicate keys. is this really expected behavior? class Model
{
public function __construct(
private ORM $orm,
private EntityManagerInterface $em,
)
{
}
public function method(Symbol $symbol): void
{
/** @var ShortTimeSeriesMetadata|null $metadata */
$metadata = $this->orm->getRepository(ShortTimeSeriesMetadata::class)
->findByPK($symbol->value);
if (!$metadata) {
return;
}
$metadata->setLastTry(new DateTimeImmutable());
// performs insert operation
$this->em->persist($metadata);
$this->em->run();
// performs update operation
$em = new EntityManager($this->orm);
$em->persist($metadata);
$em->run();
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
roxblnfk
Oct 3, 2024
Replies: 1 comment 3 replies
-
Looks like you resolve ORM via class, not interface. That's why you get a new ORM with a clean heap ant it is trying to insert the entity because it looks new for the ORM |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
MartkCz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like you resolve ORM via class, not interface. That's why you get a new ORM with a clean heap ant it is trying to insert the entity because it looks new for the ORM