I have a simple domain model as follows
Driver – key(string), run-count, unique-track-count
Track – key(string), run-count, unique-driver-count, best-time
Run – key(?), driver-key, track-key, time, boolean-driver-update, boolean-track-updated
I need to be able to update a Run and a Driver in the same transaction; as well as a Run and a Track in the same transaction (obviously to make sure i don’t update the statistics twice, or miss out on an increment counter)
Now I have tried assigning as run key, a key made up of driver-key/track-key/run-key(string)
This will let me update in one transaction the Run entity and the Driver entity.
But if I try updating the Run and Track entities together, it will complain that it cannot transact over multiple groups. It says that it has both the Driver and the Truck in the transaction and it can’t operate on both…
tx.begin(); run = pmf.getObjectById(Run.class, runKey); track = pmf.getObjectById(Track.class, trackKey); //This is where it fails; incrementCounters(); updateUpdatedFlags(); tx.commit();
Strangely enough when I do a similar thing to update Run and Driver it works fine.
Any suggestions on how else I can map my domain model to achieve the same functionality?
I think I found a lateral but still clean solution which still makes sense in my domain model.
The domain model changes slightly as follows:
I can now update atomically (i.e. precisely) the statistics of a Track with the statistics from a Run, immediately or in my own time. (And same with the Driver / Run statistics).
So basically I have to expand a little bit the way I model my problem, in a non-conventional relational way. What do you think?