spring-statemachine icon indicating copy to clipboard operation
spring-statemachine copied to clipboard

JpaRepositoryStateMachinePersist is not using the contextObj when building machine state

Open kaarelm opened this issue 6 years ago • 5 comments

When using the DefaultStateMachinePersister with JpaRepositoryStateMachinePersist to persist a statemachine then the machineId is taken from the StateMachineContext object and the contextObj is unused - link to code

When restoring the statemachine, then the state is read from the DB using getRepository().findById(contextObj.toString()) - link to code

As a result the statemachine cannot be restored using the contextObj because when it was first persisted the machineId was used as the primary key and nothing is found from the DB when restoring and trying to use the findById(contextObj.toString())

Using Spring Statemachine version 2.1.1

kaarelm avatar Apr 22 '19 09:04 kaarelm

Any comment @jvalkeal ?

kaarelm avatar May 09 '19 09:05 kaarelm

I was looking at the JpaRepositoryStateMachinePersist and noticed that the setMachineId is using the StateMachineContext to get the stored ID and persist this; however, in the MongoDbRepositoryStateMachine AND RedisRepositoryStateMachineId it is using contextObject itself. Is that on purpose? @jvalkeal

CADdesign avatar Sep 12 '19 20:09 CADdesign

@jvalkeal I can do a pull request and make this change, but want to confirm if the JPA is different by design. Can't find any documentation on the matter.

CADdesign avatar Sep 13 '19 16:09 CADdesign

I have the same question,any update?

dsc6636926 avatar Jan 21 '21 14:01 dsc6636926

Same error 3.2.0, any update to fix the error ? Can do the PR

Charon11 avatar Jul 21 '23 13:07 Charon11