I have some JPA (EclipseLink) entities called Experiment
, ExperimentSetup
and ExperimentResults
. An Experiment
entity has a one-to-many relationship to ExperimentSetup
and ExperimentSetup
has a one-to-many relationship to ExperimentResult
. When a Experiment
gets persisted ExperimentSetup
and ExperimentResults
should also be persisted. for this I use the CascadeType.PERSIST
setting in the @OneToMany
annotation. It does persist the objects I want but in a different order then I expected (that is in the order the had in the ArrayList representing the entities one-to-many relationship).
So what I'm wondering is if there is a way to make the entities be inserted to the database in the order they have in the collection, while still using CascadeType.PERSIST?
My classes (simplified):
@Entity
public class Experiment implements Serializable {
@Id
private String eid;
@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.REMOVE}, mappedBy = "expEID")
private List<ExperimentSetup> setupList;
@Column
private String name;
Getters and setter...
}
@Entity
public class ExperimentSetup implements Serializable {
@Id
private String id;
@OneToMany(mappedBy = "setupId",cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
private List<ExperimentResults> results;
@Column
private Integer setupValue;
Getters and setter...
}
@Entity
public class ExperimentResults implements Serializable {
@Id
private String id;
@Columns Integer data;
Getters and setter...
}