For our project we have a layer architecture. The DAO-Layer communicates with the Database and gets the stored Entities. The Service-Layer communicates with the DAO-Layer to get the entities and implements more complex methods. Then the View-Layer communicates with the Serivce-Layer to get the needed information.
Part of the Entity:
@Entity
public class Operation implements Serializable {
private Integer id;
@GeneratedValue
@Id
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
private List<Participation> participations;
@OneToMany
public List<Participation> getParticipations() {
return participations;
}
public void setParticipations(List<Participation> participations) {
this.participations = participations;
}
DAO-Layer:
@Override
public Operation read(int id) {
return this.em.find(Operation.class, id);
}
Service-Layer:
@Override
public Operation getOperation(Integer operationId)
{
Operation operation = operationDAO.read(operationId);
//operation.getParticipations();
return operation;
}
View-Layer:
Operation o = opService.getOperation(operationId);
Using this without the operation.getParticipations(); on the View-Layer the participation-List is missing. If i add the stupid code then the object is forwarded correctly and the participation list is available.
I cant explain to myself why the object isn’t forwarded correctly? Can you help me? Thx in advance.
Edit: All other attributes/fields of the object are forwarded correctly (may important to know)
For
@OneToManydefaultFetchTypeisLAZY.And The
LAZYstrategy is a hint to the persistence provider that data should be fetched lazily when it is first accessed.