public class ATestCase extends TestCase {
protected static EntityManager em;
protected static EntityManagerFactory emf;
public void setUp()
{
emf = Persistence.createEntityManagerFactory("model");
em = emf.createEntityManager();
}
public void tearDown()
{
emf.close();
em.close();
}
public void save(Object o)
{
em.getTransaction().begin();
em.persist(o);
em.getTransaction().commit();
}
public A merge(A o)
{
em.getTransaction().begin();
A o1 =em.merge(o);
em.getTransaction().commit();
return o1;
}
public void testProcessDefinition() {
ProcessDefinition processDefinition = new ProcessDefinition("auction1");
Action action1 =new Action();
action1.setName("auction1");
processDefinition.addAction(action1);
save(processDefinition);
//
processDefinition.setName("auction");
processDefinition.removeAction(action1); // notice1
processDefinition =merge(processDefinition); // notice2
}
}
ProcessDefinition
@Entity(access = AccessType.FIELD)
@Inheritance(discriminatorValue = "process-definition")
public class ProcessDefinition extends GraphElement implements NodeCollection {
//..
@OneToMany(cascade = CascadeType.ALL, mappedBy = "processDefinition", fetch = FetchType.EAGER)
@MapKey(name = "name")
protected Map<String, Action> actions = null;
//..
}
Action
@Entity(access = AccessType.FIELD)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE, discriminatorType = DiscriminatorType.STRING, discriminatorValue = "action")
@Table(name = "BPM_ACTION")
@DiscriminatorColumn(name = "TYPE_", nullable = true, length = 64)
public class Action implements Parsable, Serializable {
//...
@ManyToOne
@JoinColumn(name = "PROCESSDEFINITION_")
protected ProcessDefinition processDefinition = null;
//..
}
The action1 had been removed at line notice1, but actually it hadn't been removed by the database. Is there any mistake in the test case?