Issue
I am implementing an entity class which has 2 relations one-to-many but I can't use fetch = FetchType.EAGER
for the two list.
I should use FetchType.LAZY
for both.
Is there a solution to use EAGER for both?
@OneToMany(mappedBy="fournisseur",fetch = FetchType.EAGER,cascade={ CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE} )
private List<Carburant_entree> carburant_entrees;
@OneToMany(mappedBy="user",fetch = FetchType.EAGER,cascade={ CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE} )
private List<Users> theusers;
Solution
Just use Set
in place of List
@OneToMany(mappedBy="fournisseur",fetch = FetchType.EAGER,cascade={ CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE} )
private Set<CarburantEntree> carburantEntrees;
@OneToMany(mappedBy="user",fetch = FetchType.EAGER,cascade={ CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOVE} )
private Set<Users> users;
Please, follow the Java Naming Conventntion.
Answered By - v.ladynev
Answer Checked By - David Goodson (JavaFixing Volunteer)