Problem:
Your need to make JPA Entity with @OneToMany and @ManyToOne mapping tags.
Solution:
You have tables like this:
Table "Requests":
Your need to make JPA Entity with @OneToMany and @ManyToOne mapping tags.
Solution:
You have tables like this:
Table "Requests":
Field | Type |
ID | Integer |
STEP_ID | Integer |
Table "Steps":
Field | Type |
ID | Integer |
REQUEST_ID | Integer |
Table "Requests" should have in field "Step_Id" many rows from table "Steps", and table "Steps" should have in field "Requst_Id" one row from "Requests" table.
Make JPA Entities like this:
@Entity
@Table(name="REQUESTS")
public class Requests implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
@OneToMany(mappedBy="request", fetch=FetchType.EAGER)
private Set<Steps> steps = new HashSet<Steps>();
public Requests() {
}
public long getId() {
return this.id;
}
public void setId(long id) {
this.id = id;
}
public void setSteps(Set<Steps> history) {
this.steps = steps ;
}
public Set<Steps> getSteps() {
return steps;
}
}
@Entity
@Table(name="STEPS")
public class Steps implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST}, fetch=FetchType.EAGER)
@JoinColumn(name = "REQUEST_ID")
private EoRequestsEntity request;
public Steps() {
}
public int getId() {
return this.id;
}
public void setRequest(Requests request) {
this.request = request;
}
public EoRequestsEntity getRequest() {
return request;
}
}
Tags "cascade" and "fetch" is required!
That's all!