I have a doctrine entity which has categories so to set a category to the entity i need to call
$category = $categoryRepository->find($categoryId);
$entity->addCategory($category);
Is it possible to set it without the repository with only the ID?
yes, you can use reference proxies:
$entity->addCategory($em->getReference('MyProject\Model\Category', $categoryId))