# How to prevent EntityWrittenEvent from triggering again and again?

**URL:** <https://forum.shopware.com/t/how-to-prevent-entitywrittenevent-from-triggering-again-and-again/95678>\
**Category:** Programming (EN)\
**Created:** [5. August 2022 um 11:32 UTC](https://forum.shopware.com/t/how-to-prevent-entitywrittenevent-from-triggering-again-and-again/95678 "2022-08-05T11:32:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![abinjohnedamana](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/abinjohnedamana/32/17378_2.png) [@abinjohnedamana](https://forum.shopware.com/u/abinjohnedamana)\
**Post date:** [5. August 2022 um 11:32 UTC](https://forum.shopware.com/t/how-to-prevent-entitywrittenevent-from-triggering-again-and-again/95678/1 "2022-08-05T11:32:46Z")

</div>

If you want to subscribe an EntityWrittenEvent and update the same entity. the event sucriber will work as a loop.

In order to prevent this, you can use the Shopware\Core\Framework\DataAbstractionLayer\VersionManager

class

for eg:

```auto
public function update(array $data, Context $context)
    {
        $affected = $this->versionManager->update($this->productDefinition , $data, WriteContext::createFromContext($context));

    }

    public function upsert(array $data, Context $context)
    {
        $affected = $this->versionManager->upsert($this->productDefinition , $data, WriteContext::createFromContext($context));
    }

    public function create(array $data, Context $context)
    {
        $affected = $this->versionManager->insert($this->productDefinition, $data, WriteContext::createFromContext($context));
    }

```
