I have the following JPA entities with bidirectional mapping. I'm trying to fetch all the featureGroup into a DTO.
If I do findAll at featureGroup and iteratinng to get its features. Its not coming. I'm not yet more familiar with JPA. Is my approach is correct?
Below are my entities.
@Entity
@Table(name="application")
@Data
class Application{
@Id @GeneratedValue(strategy=GenerationType.IDENTITY) id;
name;
@OneToMany(mappedBy="application")
private Set<AppFeatureGroup> appFeatureGroup;
}
then
@Entity
@Table(name="appfeaturegroup")
@Data
class AppFeatureGroup {
@Id @GeneratedValue(strategy=GenerationType.IDENTITY) id;
title;
@OneToMany(mappedBy="appfeaturegroup")
private Set<AppFeature> appFeature;
@ManyToOne(cascade=CascadeType.ALL) @JoinColumn(name="id", insertable=false, updatable=false)
private Application application;
}
then
@Entity
@Table(name="appfeature")
@Data
class AppFeature{
@Id @GeneratedValue(strategy=GenerationType.IDENTITY) id;
title;
@OneToMany(mappedBy="appFeature")
private Set<AppSubFeature> appSubFeature;
@ManyToOne(cascade=CascadeType.ALL) @JoinColumn(name="id", insertable=false, updatable=false)
private AppFeatureGroup appFeatureGroup;
}
and
@Entity
@Table(name="appsubfeature")
@Data
class AppSubFeature{
@Id @GeneratedValue(strategy=GenerationType.IDENTITY) id;
title;
@ManyToOne(cascade=CascadeType.ALL) @JoinColumn(name="id", insertable=false, updatable=false)
private AppFeature appFeature;
}
then
I try to get the objects like below:
List<AppFeatureGroup> appFeatureGroupList = appFeatureGroupRepository.finAll()
//Also tried from Application application = findById(id) and from application also I tried to get the deep objects
for(AppFeatureGroup appFeatureGroup : appFeatureGroupList){
//I get id and title. But,
Set<AppFeature> appFeature = appFeatureGroup.getAppFeature();//This is empty
}
Is it not correct what I implemented is? I tried with fetch=FethType.EAGER
also. But still not working.