On 2010-10-26 22.11, Ronnie Nessa wrote:
1. Is using unitOfWork.create(MyEntity.class, "myReadableIdentifier") a
good solution to support my use case?

Yes, and I do the exact same thing: on startup I check whether some bootstrap entities are available (in EventSourcing all events have to come from entities, so bootstrapping the first one is mandatory), and if not I use the uow.newEntity(MyEntity.class,SOMECONSTANTID) method.

In fact, I ALWAYS use the newEntity(class,id) method, since entities are always created as a response to an event, and the event MUST have the id of the new entity. Otherwise replay of events wouldn't create the same state.

2. Is there an easy way to change the identity of an entity that already
exist in the EntityStore?

Not really, no. You can always create a copy of it and store it, but the references to it is the main issue. I have a few usecases of "replace A with B" and "merge A into B" and what I do is to basically query for all known references to A and set them to B in code.

3. How do you use the MigrationOperation to update entities when you
don´t know the id of the entities until runtime? Specifically; How do
you get access to application components from an instance of a
MigrationOperation?

Migration is run before the application is really started, in a sense, so you're only allowed to work on state. If you need anything else, then I recommend doing a service with .instantiateOnStartup(), and implement the more complex logic in the activate() method.

/Rickard

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to