Forum system implementation
How about something like this there is some checking that needs to be done because I inverse the $isPost bool and that could be buggy

public function postPersist(LifecycleEventArgs $args)
{
    $entity = $args-&gt;getObject();
    $entityManager = $args-&gt;getObjectManager();

    $isPost = $entity instanceof Post;

    $thread = $isPost ? $post-&gt;getThread() : $entity;

    $details = $isPost ? $entity : $thread;

    $category = $thread-&gt;getCategory(); 
    $category-&gt;setLastPostThreadTitle($thread-&gt;getTitle()); 
    $category-&gt;setLastPostThreadSlug($thread-&gt;getSlug()); 
    $category-&gt;setLastPostBody($details-&gt;getBody());
    $category-&gt;setLastPosterUsername($details-&gt;getUser()-&gt;getUsername());
    $category-&gt;setLastPostCreatedAt($details-&gt;getCreatedAt());

    //NOTE the inversion of the isPost bool
    //TODO Test this
    $category-&gt;setIsLastPostOp(!$isPost);

    if($isPost){         
        $category-&gt;setPosts($category-&gt;getPosts() + 1);
    }

    $entityManager-&gt;merge($category);           
    $entityManager-&gt;flush();
}