I have defined two classes Listing and Gallery corresponding to two different Tables with same name. Gallery has a foreign key to Listing
Listing
@Entity
@Table(name = "listing")
public class Listing implements java.io.Serializable {
......
@OneToMany(cascade = {CascadeType.MERGE,CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.REFRESH}, fetch = FetchType.EAGER, mappedBy = "listing")
public Set<Gallery> getGalleries() {
return this.galleries;
}
......
}
In my code the first time I am retrieving Listing, I saw that it also issues queries to retrieve the gallery corresponding to each listing.
Query query=entityManager.createQuery("select listing from Listing as listing where listing.user=:propertyValue");
query.setParameter("propertyValue", user);
listings=query.getResultList();
but the second time when the code runs. it only issues queries to retrieve the listing and not the galleries, what am i missing here?