event-centric / EventCentric.Core

Event Sourcing and CQRS in PHP
MIT License
126 stars 9 forks source link

OptimisticConcurrencyFailed #2

Open revati opened 10 years ago

revati commented 10 years ago

Hello, Mathias, when i fetch existing object from event store and after updating it try to persist it, i get OptimisticConcurrencyFailed exception.

$order = $repository->get( $uuid );
$order->pay(50);
$unitOfWork->commit();

in EventCentric\UnitOfWork\UnitOfWork::persistAggregate by default it always creates new streams rather than opens it if needed, so it eventually calls EventCentric\EventStore\EventStream::create which does not store committedEventEnvelopes as open method does.

I think thats the problem, because changing EventCentric\UnitOfWork\UnitOfWork 114 line to fallowing:

 $stream = $this->eventStore->openStream($aggregate->getAggregateContract(), $aggregate->getAggregateId());

everything works fine.

mathiasverraes commented 10 years ago

Thanks, a lot of that stuff is unfinished. I'm actually experimenting with an easier design that should prevent these kinds of issues.