Fix JPA actions
- Change JpaRepositoryTransition and JpaRepositoryState to use ManyToMany instead of OneToMany for actions Set. - Fixes #280
This commit is contained in:
@@ -23,7 +23,7 @@ import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
import org.springframework.statemachine.data.RepositoryState;
|
||||
@@ -56,13 +56,13 @@ public class JpaRepositoryState extends RepositoryState {
|
||||
@OneToOne(fetch = FetchType.EAGER)
|
||||
private JpaRepositoryState parentState;
|
||||
|
||||
@OneToMany(fetch = FetchType.EAGER)
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
private Set<JpaRepositoryAction> stateActions;
|
||||
|
||||
@OneToMany(fetch = FetchType.EAGER)
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
private Set<JpaRepositoryAction> entryActions;
|
||||
|
||||
@OneToMany(fetch = FetchType.EAGER)
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
private Set<JpaRepositoryAction> exitActions;
|
||||
|
||||
@ElementCollection(fetch = FetchType.EAGER, targetClass = String.class)
|
||||
|
||||
@@ -22,7 +22,7 @@ import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
import org.springframework.statemachine.data.RepositoryTransition;
|
||||
@@ -56,7 +56,7 @@ public class JpaRepositoryTransition extends RepositoryTransition {
|
||||
private String event;
|
||||
private TransitionKind kind;
|
||||
|
||||
@OneToMany(fetch = FetchType.EAGER)
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
private Set<JpaRepositoryAction> actions;
|
||||
|
||||
@OneToOne(fetch = FetchType.EAGER)
|
||||
|
||||
@@ -194,6 +194,49 @@ public class JpaRepositoryTests extends AbstractRepositoryTests {
|
||||
assertThat(transition2.getActions().size(), is(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepository6() {
|
||||
context.register(TestConfig.class);
|
||||
context.refresh();
|
||||
|
||||
JpaActionRepository actionsRepository = context.getBean(JpaActionRepository.class);
|
||||
JpaStateRepository statesRepository = context.getBean(JpaStateRepository.class);
|
||||
JpaTransitionRepository transitionsRepository = context.getBean(JpaTransitionRepository.class);
|
||||
|
||||
JpaRepositoryAction action1 = new JpaRepositoryAction();
|
||||
action1.setName("action1");
|
||||
actionsRepository.save(action1);
|
||||
assertThat(actionsRepository.count(), is(1l));
|
||||
|
||||
JpaRepositoryAction action2 = new JpaRepositoryAction();
|
||||
action2.setName("action2");
|
||||
actionsRepository.save(action2);
|
||||
assertThat(actionsRepository.count(), is(2l));
|
||||
|
||||
JpaRepositoryState stateS1 = new JpaRepositoryState("S1");
|
||||
stateS1.setEntryActions(new HashSet<>(Arrays.asList(action1, action2)));
|
||||
stateS1.setExitActions(new HashSet<>(Arrays.asList(action1, action2)));
|
||||
JpaRepositoryState stateS2 = new JpaRepositoryState("S2");
|
||||
stateS2.setParentState(stateS1);
|
||||
stateS2.setStateActions(new HashSet<>(Arrays.asList(action1, action2)));
|
||||
JpaRepositoryState stateS3 = new JpaRepositoryState("S3");
|
||||
stateS3.setParentState(stateS1);
|
||||
stateS3.setExitActions(new HashSet<>(Arrays.asList(action1, action2)));
|
||||
statesRepository.save(stateS1);
|
||||
statesRepository.save(stateS2);
|
||||
statesRepository.save(stateS3);
|
||||
|
||||
JpaRepositoryTransition transition1 = new JpaRepositoryTransition(stateS1, stateS2, "E1");
|
||||
transition1.setActions(new HashSet<>(Arrays.asList(action1, action2)));
|
||||
transitionsRepository.save(transition1);
|
||||
assertThat(transitionsRepository.count(), is(1l));
|
||||
|
||||
JpaRepositoryTransition transition2 = new JpaRepositoryTransition(stateS2, stateS3, "E2");
|
||||
transition2.setActions(new HashSet<>(Arrays.asList(action1, action2)));
|
||||
transitionsRepository.save(transition2);
|
||||
assertThat(transitionsRepository.count(), is(2l));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AnnotationConfigApplicationContext buildContext() {
|
||||
return new AnnotationConfigApplicationContext();
|
||||
|
||||
Reference in New Issue
Block a user