设置实体子实体而不从存储库加载

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))

http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/advanced-configuration.html#reference-proxies