0 Replies Latest reply on Aug 17, 2009 4:50 PM by Jubril Adisa

    Problem using Fetch Type Eager

    Jubril Adisa Novice

      I have defined two classes Listing and Gallery corresponding to two different Tables with same name. Gallery has a foreign key to Listing

      @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);

      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?