Almost every post I read states that I should be working on objects using Magento 2 repositories rather that instantiating objects using Magento 2 object factories.
That's what I started to do, and all was great until I wrote an small extension to programatically create a shipment whilst also writing a comment to the orders history table.
I would have expected to do something like this in a database transaction, so if there's a failure everything gets rolled back, but I just can't see how to use database transactions with repositories.
If I do something like
$order = $this->orderRepository->get($orderId);
$order->setSomething('something');
$transaction = $this->transactionFactory->create();
$transaction->addObject($order);
I get a warning in phpStorm of: Expected \Magento\Framwork\Abstract\Model, got \Magento\Sales\Api\Data\OrderInterface. Basically it looks like the database transaction object is expecting factory generated Models rather than repository generated objects. Does that mean that repositories don't actually support database transactions?