title: Spring state machine to manage JPA entity
body: <p>I have a <code>Task</code> JPA <code>@Entity</code> which has field <code>state</code> - so it looks like state machine could be good abstraction to work with. The <code>state</code> may change by calling a REST endpoint in form like <code>PUT /api/tasks/{id}/state</code>. I wanted to utilize the concept of <code>Actions</code>, <code>Guards</code> as it looks like nice abstractions. I guess I need something along:</p>
  
  <ol>
  <li>In the REST endpoint create (or rather restore?) the state machine in state corresponding to the current <code>Tasks</code>'s state and associate the JPA entity with it's context so it is available for <code>Action</code>s which can change the <code>state</code> task's state field (and others) and persist it back through <code>Repository</code></li>
  <li>Send the event representing transition to new state</li>
  </ol>
  
  <p>I assume point 1. will create the machine through builder as with @EnableStateMachineFactory you cannot really <em>create</em> the machine in particular state (which kind of make sense). I'm unclear how to add the entity which I probably <code>findOne</code> in <code>@Repository</code> to the state machine's context.</p>
  
  <p>Would that be the right approach? Is there a sample covering this? I was pretty honest in going through the existing samples and didn't find anything similar.</p>