I got several Projects with an ID
and a Name
. A Project contains several Models, while each Model contains several Simulations.
I thought about saving a HashMap
in my Project entity
private HashMap<Model, ArrayList<Simulation>> modelSimulation = new HashMap<>();
But I actually have no clue what Annotation to use.. I tried @CollectionOfElements
but I just got this exception:
Illegal attempt to map a non collection as a @OneToMany..
Project:
@Entity
public class Project {
private final IntegerProperty pID = new SimpleIntegerProperty();
private final StringProperty name = new SimpleStringProperty();
private HashMap<Model, ArrayList<Simulation>> modelSimulation = new HashMap<>();
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int getsID() {
return pID.get();
}
@Column(name = "NAME")
public String getName() {
return name.get();
}
public HashMap<Model, ArrayList<Simulation>> getModelSimulation() {
return modelSimulation;
}
public void setModelSimulation(
HashMap<Model, ArrayList<Simulation>> modelSimulation) {
this.modelSimulation = modelSimulation;
}
}
Simulation
@Entity
public class Simulation {
private final IntegerProperty sID = new SimpleIntegerProperty();
private final StringProperty name = new SimpleStringProperty();
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int getsID() {
return sID.get();
}
@Column(name = "NAME")
public String getName() {
return name.get();
}
public void setName(String name) {
this.name.set(name);
}
}
Model
@Entity
public class Model {
private final IntegerProperty mID = new SimpleIntegerProperty();
private final StringProperty name = new SimpleStringProperty();
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int getsID() {
return mID.get();
}
@Column(name = "NAME")
public String getName() {
return name.get();
}
}
This is what I want to have as tables:
Project
ID Name
1 Project A
2 Project B
Model
ID Name
1 Model A
2 Model B
Simulation
ID Name
1 Simulation A
2 Simulation B
3 Simulation C
IntermediateTable
ProjectID ModelID SimulationID
1 -- 1 -- 1
1 -- 2 -- 2
1 -- 1 -- 3