views:

44

answers:

1

Hi, I have an entity which has a collection as one of its attributes. That collection is mapped with a @ManyToMany annotation with fetch type lazy. The target entity also has collections as attributes, some are @OneToMany and some are @ManyToMany. When fetching the first entity (via entityManager.find(id)) its collection attribute is populated and furthermore the elements of the collection are fully populated as well (i.e. the collections a filled) so i get many canonicalized objects. As I understand describing an attribute as lazy fetched should prevent the collection from being filled. Am I wrong or just doing something wrong?

Thank you.

The entities (only two here for the example):

@Entity
@Table(name="buys")
@XStreamAlias("buy")
public class Buy implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public enum AutoMode {AUTO, MANUAL};
    public enum Bool {FALSE,TRUE};
    public enum Frequency {FREQ1, FREQ2};
    public enum Status {STATUS1, STATUS2};

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @XStreamAsAttribute
    @Column(name = "id")
    private Long id;

    /*
    @JoinColumn(name="agency_id")
    @XStreamAlias("agencyId")
    @ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    private Agency agencyId;
    */

    @Column(name = "agency_id")
    @XStreamAlias("agencyId")
    private long agencyId;

    @Column(name = "auction_date")
    @Temporal(TemporalType.DATE)
    @XStreamAlias("auction")
    private Date auctionDate;

    @Column(name = "pre_auction_date")
    @Temporal(TemporalType.DATE)
    @XStreamAlias("pre-auction")
    private Date preAuctionDate;

    @Column(name = "send_feedback_auto_mode")
    @XStreamAlias("auto-send")
    @Enumerated(EnumType.ORDINAL)
    private AutoMode sendFeedbackAutoMode;

    @Column(name = "campaign_budget")
    @XStreamAlias("budget")
    private Integer budget;

    @Column(name = "price_ceiling")
    @XStreamAlias("price-ceiling")
    @Min(value = 1, message = "Price ceiling should be greater then 0")
    private Double priceCeiling;

    /*
    @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinColumn(name="campaign_id")
    private Campaign campaign;
    */

    @Column(name = "campaign_id")
    @XStreamAlias("campaignId")
    private long campaign;

    @Column(name = "avg_bid_received")
    @XStreamAlias("avgBigReceived")
    private double avgBid;

    @Column(name = "maximum_unique_users")
    @XStreamAlias("maxUniqueUsers")
    private int maxUniqueUsers;

    @Column(name = "optimize_method")
    @XStreamAlias("optimzeMethod")
    private int optimzeMethod;

    @Column(name = "frequency")
    @XStreamAlias("frequency")
    private int frequency;

    @Column(name = "frequency_type")
    @XStreamAlias("frequency_type")
    @Enumerated(EnumType.ORDINAL)
    private Frequency frequencyType;

    @Column(name = "additional_info")
    @XStreamAlias("additionalInfo")
    private String additionalInfo;

    @Column(name = "support_oob")
    @XStreamAlias("oob")
    @Enumerated(EnumType.ORDINAL)
    private Bool supportOOB;

    @Column(name = "support_in_banner")
    @XStreamAlias("ib")
    @Enumerated(EnumType.ORDINAL)
    private Bool supportIB;

    @Column(name = "status")
    @XStreamAlias("status")
    @Enumerated(EnumType.ORDINAL)
    private Status status;

    @Version
    @Column(name = "version")
    @XStreamAsAttribute
    private Integer version;

    @ManyToMany(fetch=FetchType.LAZY,cascade = { CascadeType.MERGE, CascadeType.PERSIST})
    @JoinTable( name="buy_ad_sizes", joinColumns=@JoinColumn(name="buy_id"),inverseJoinColumns=@JoinColumn(name="ad_size_id"))
    @XStreamAlias("adSizes")
    private List<AdUnit> adSizes;

    @ManyToMany(fetch=FetchType.LAZY,cascade = { CascadeType.MERGE, CascadeType.PERSIST})
    @JoinTable( name="buy_profiles", joinColumns=@JoinColumn(name="buy_id"),inverseJoinColumns=@JoinColumn(name="profile_id"))
    @XStreamAlias("profiles")
    private List<Profile> profiles;

    @JoinColumn(name="buy_id")
    @OneToMany(fetch=FetchType.LAZY,cascade = { CascadeType.MERGE, CascadeType.PERSIST})
    @XStreamAlias("mediaPlans")
    private List<MediaPlan> mediaPlans;

    @JoinColumn(name = "buy_id")
    @OneToMany(fetch=FetchType.LAZY,cascade = { CascadeType.MERGE, CascadeType.PERSIST})
    @XStreamAlias("publisherProposals")
    private List<PublisherProposal> publisherProposals;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public Date getAuctionDate() {
        return auctionDate;
    }

    public void  setAuctionDate(Date auctionDate) {
         this.auctionDate = auctionDate;
    }

    public Date getPreAuctionDate() {
        return preAuctionDate;
    }

    public void  setPreAuctionDate(Date preAuctionDate) {
         this.preAuctionDate = preAuctionDate;
    }

    public Integer getBudget() {
        return budget;
    }

    public void setBudget(Integer budget) {
        this.budget = budget;
    }

    public Double getPriceCeiling() {
        return priceCeiling;
    }

    public void setPriceCeiling(Double priceCeiling) {
        this.priceCeiling = priceCeiling;
    }

    public AutoMode getSendFeedbackAutoMode() {
        return sendFeedbackAutoMode;
    }

    public void setSendFeedbackAutoMode(AutoMode sendFeedbackAutoMode) {
        this.sendFeedbackAutoMode = sendFeedbackAutoMode;
    }

    public double getAvgBid() {
        return avgBid;
    }

    public void setAvgBid(double avgBid) {
        this.avgBid = avgBid;
    }

    public int getMaxUniqueUsers() {
        return maxUniqueUsers;
    }

    public void setMaxUniqueUsers(int maxUniqueUsers) {
        this.maxUniqueUsers = maxUniqueUsers;
    }

    public int getOptimzeMethod() {
        return optimzeMethod;
    }

    public void setOptimzeMethod(int optimzeMethod) {
        this.optimzeMethod = optimzeMethod;
    }

    public int getFrequency() {
        return frequency;
    }

    public void setFrequency(int frequency) {
        this.frequency = frequency;
    }

    public Frequency getFrequencyType() {
        return frequencyType;
    }

    public void setFrequencyType(Frequency frequencyType) {
        this.frequencyType = frequencyType;
    }

    public String getAdditionalInfo() {
        return additionalInfo;
    }

    public void setAdditionalInfo(String additionalInfo) {
        this.additionalInfo = additionalInfo;
    }

    public Bool getSupportOOB() {
        return supportOOB;
    }

    public List<AdUnit> getAdSizes() {
        return adSizes;
    }

    public void setAdSizes(List<AdUnit> adSizes) {
        this.adSizes = adSizes;
    }

    public void setSupportOOB(Bool supportOOB) {
        this.supportOOB = supportOOB;
    }

    public Bool getSupportIB() {
        return supportIB;
    }

    public void setSupportIB(Bool supportIB) {
        this.supportIB = supportIB;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public List<Profile> getProfiles() {
        return profiles;
    }

    public void setProfiles(List<Profile> profiles) {
        this.profiles = profiles;
    }

    public List<MediaPlan> getMediaPlans() {
        return mediaPlans;
    }

    public void setMediaPlans(List<MediaPlan> mediaPlans) {
        this.mediaPlans = mediaPlans;
    }

    public List<PublisherProposal> getPublisherProposals() {
        return publisherProposals;
    }

    public void setPublisherProposals(List<PublisherProposal> publisherProposals) {
        this.publisherProposals = publisherProposals;
    }

    public long getAgencyId() {
        return agencyId;
    }

    public void setAgencyId(long agencyId) {
        this.agencyId = agencyId;
    }

    public long getCampaign() {
        return campaign;
    }

    public void setCampaign(long campaign) {
        this.campaign = campaign;
    }



}

second entity:

@Entity
@Table(name = "ad_units")
@XStreamAlias("adunit")
public class AdUnit {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    @XStreamAsAttribute
    private Long id;

    @Column(unique=true, nullable=false )
    @XStreamAsAttribute
    private String name;

    @Column(name="full_name",nullable=false )
    @XStreamAlias("full-name")
    private String fullName;

    @XStreamAlias("width")
    private Integer width;

    @XStreamAlias("height")
    private Integer height;

    @XStreamAlias("type")
    private String type;

    @ManyToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, mappedBy = "adSizes", targetEntity = Publisher.class)
    private List<Publisher> publishers;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public Integer getWidth() {
        return width;
    }

    public void setWidth(Integer width) {
        this.width = width;
    }

    public Integer getHeight() {
        return height;
    }

    public void setHeight(Integer height) {
        this.height = height;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public List<Publisher> getPublishers() {
        return publishers;
    }

    public void setPublishers(List<Publisher> publishers) {
        this.publishers = publishers;
    }
}

the returned object:

<buy id="1" version="0">
  <agencyId>1</agencyId>
  <auction class="sql-date">2010-09-25</auction>
  <pre-auction class="sql-date">2010-09-25</pre-auction>
  <auto-send>AUTO</auto-send>
  <budget>1000</budget>
  <price-ceiling>5.0</price-ceiling>
  <campaignId>0</campaignId>
  <avgBigReceived>5.5</avgBigReceived>
  <maxUniqueUsers>7</maxUniqueUsers>
  <optimzeMethod>3</optimzeMethod>
  <frequency>0</frequency>
  <frequency__type>FREQ1</frequency__type>
  <additionalInfo>none</additionalInfo>
  <oob>TRUE</oob>
  <ib>FALSE</ib>
  <status>STATUS1</status>
  <adSizes>
    <adunit id="1" name="300X250">
      <full-name>300 x 250 IMU - (Medium Rectangle)</full-name>
      <width>300</width>
      <height>250</height>
      <type>Popups &amp; Rectangles</type>
      <publishers>
        <publisher id="2">
          <name>publisher2</name>
          <profiles/>
          <proposals>
            <proposal id="0" version="0">
              <publisherId>2</publisherId>
              <buyId>1</buyId>
              <creationDate class="sql-date">2010-11-11</creationDate>
              <lastUpdated class="sql-date">2010-11-11</lastUpdated>
              <cpm>5.0</cpm>
              <minimumSpend>100</minimumSpend>
              <info>none</info>
              <revealUsers>FALSE</revealUsers>
              <status>STATUS1</status>
              <mediaPlanProposals/>
            </proposal>
          </proposals>
          <adSizes>
            <adunit reference="../../../.."/>
            <adunit id="3" name="240X400">
              <full-name>240 x 400 IMU - (Vertical Rectangle)</full-name>
              <width>240</width>
              <height>240</height>
              <type>Popups &amp; Rectangles</type>
              <publishers>
                <publisher reference="../../../.."/>
              </publishers>
            </adunit>
          </adSizes>
        </publisher>
      </publishers>
    </adunit>
  </adSizes>
  <profiles/>
  <mediaPlans/>
  <publisherProposals>
    <proposal reference="../../adSizes/adunit/publishers/publisher/proposals/proposal"/>
  </publisherProposals>
</buy>

As you can see the object contains the collection which were defined as lazy fetched and furthermore the collections inside the collections are fetched.

The debug output with queries:

[http-8080-1] DEBUG org.hibernate.SQL - select buy0_.id as id0_0_, buy0_.additional_info as additional2_0_0_, buy0_.agency_id as agency3_0_0_, buy0_.auction_date as auction4_0_0_, buy0_.avg_bid_received as avg5_0_0_, buy0_.campaign_budget as campaign6_0_0_, buy0_.campaign_id as campaign7_0_0_, buy0_.frequency as frequency0_0_, buy0_.frequency_type as frequency9_0_0_, buy0_.maximum_unique_users as maximum10_0_0_, buy0_.optimize_method as optimize11_0_0_, buy0_.pre_auction_date as pre12_0_0_, buy0_.price_ceiling as price13_0_0_, buy0_.send_feedback_auto_mode as send14_0_0_, buy0_.status as status0_0_, buy0_.support_in_banner as support16_0_0_, buy0_.support_oob as support17_0_0_, buy0_.version as version0_0_ from buys buy0_ where buy0_.id=?
Hibernate: select buy0_.id as id0_0_, buy0_.additional_info as additional2_0_0_, buy0_.agency_id as agency3_0_0_, buy0_.auction_date as auction4_0_0_, buy0_.avg_bid_received as avg5_0_0_, buy0_.campaign_budget as campaign6_0_0_, buy0_.campaign_id as campaign7_0_0_, buy0_.frequency as frequency0_0_, buy0_.frequency_type as frequency9_0_0_, buy0_.maximum_unique_users as maximum10_0_0_, buy0_.optimize_method as optimize11_0_0_, buy0_.pre_auction_date as pre12_0_0_, buy0_.price_ceiling as price13_0_0_, buy0_.send_feedback_auto_mode as send14_0_0_, buy0_.status as status0_0_, buy0_.support_in_banner as support16_0_0_, buy0_.support_oob as support17_0_0_, buy0_.version as version0_0_ from buys buy0_ where buy0_.id=?

[http-8080-1] DEBUG org.hibernate.pretty.Printer - com.legolas.model.Buy{budget=1000, supportIB=0, avgBid=5.5, status=0, priceCeiling=5.0, maxUniqueUsers=7, optimzeMethod=3, frequency=0, additionalInfo=none, agencyId=1, frequencyType=0, version=0, sendFeedbackAutoMode=0, id=1, mediaPlans=<uninitialized>, adSizes=<uninitialized>, profiles=<uninitialized>, campaign=0, supportOOB=1, publisherProposals=<uninitialized>, preAuctionDate=25  september 2010, auctionDate=25  september 2010}

[http-8080-1] DEBUG org.hibernate.SQL - select adsizes0_.buy_id as buy1_1_, adsizes0_.ad_size_id as ad2_1_, adunit1_.id as id1_0_, adunit1_.full_name as full2_1_0_, adunit1_.height as height1_0_, adunit1_.name as name1_0_, adunit1_.type as type1_0_, adunit1_.width as width1_0_ from buy_ad_sizes adsizes0_ left outer join ad_units adunit1_ on adsizes0_.ad_size_id=adunit1_.id where adsizes0_.buy_id=?
Hibernate: select adsizes0_.buy_id as buy1_1_, adsizes0_.ad_size_id as ad2_1_, adunit1_.id as id1_0_, adunit1_.full_name as full2_1_0_, adunit1_.height as height1_0_, adunit1_.name as name1_0_, adunit1_.type as type1_0_, adunit1_.width as width1_0_ from buy_ad_sizes adsizes0_ left outer join ad_units adunit1_ on adsizes0_.ad_size_id=adunit1_.id where adsizes0_.buy_id=?

[http-8080-1] DEBUG org.hibernate.SQL - select publishers0_.adsize_id as adsize2_1_, publishers0_.publisher_id as publisher1_1_, publisher1_.publisher_id as id5_0_, publisher1_1_.name as name5_0_, publisher1_.name as name14_0_ from publishers_adsizes publishers0_ left outer join publishers publisher1_ on publishers0_.publisher_id=publisher1_.publisher_id left outer join accounts publisher1_1_ on publisher1_.publisher_id=publisher1_1_.id where publishers0_.adsize_id=?
Hibernate: select publishers0_.adsize_id as adsize2_1_, publishers0_.publisher_id as publisher1_1_, publisher1_.publisher_id as id5_0_, publisher1_1_.name as name5_0_, publisher1_.name as name14_0_ from publishers_adsizes publishers0_ left outer join publishers publisher1_ on publishers0_.publisher_id=publisher1_.publisher_id left outer join accounts publisher1_1_ on publisher1_.publisher_id=publisher1_1_.id where publishers0_.adsize_id=?

[http-8080-1] DEBUG org.hibernate.SQL - select profiles0_.publisher_id as publisher3_1_, profiles0_.id as id1_, profiles0_.id as id9_0_, profiles0_.profile_id as profile2_9_0_, profiles0_.publisher_id as publisher3_9_0_, profiles0_.reach as reach9_0_, profiles0_.stamped as stamped9_0_, profiles0_.targeting_name as targeting6_9_0_, profiles0_.users_on_site as users7_9_0_ from publisher_profiles profiles0_ where profiles0_.publisher_id=?
Hibernate: select profiles0_.publisher_id as publisher3_1_, profiles0_.id as id1_, profiles0_.id as id9_0_, profiles0_.profile_id as profile2_9_0_, profiles0_.publisher_id as publisher3_9_0_, profiles0_.reach as reach9_0_, profiles0_.stamped as stamped9_0_, profiles0_.targeting_name as targeting6_9_0_, profiles0_.users_on_site as users7_9_0_ from publisher_profiles profiles0_ where profiles0_.publisher_id=?

[http-8080-1] DEBUG org.hibernate.SQL - select proposals0_.publisher_id as publisher9_1_, proposals0_.id as id1_, proposals0_.id as id4_0_, proposals0_.additional_info as additional2_4_0_, proposals0_.buy_id as buy3_4_0_, proposals0_.cpm as cpm4_0_, proposals0_.creation_date as creation5_4_0_, proposals0_.last_updated as last6_4_0_, proposals0_.minimum_spend as minimum7_4_0_, proposals0_.proposal_status as proposal8_4_0_, proposals0_.publisher_id as publisher9_4_0_, proposals0_.reveal_num_of_users as reveal10_4_0_, proposals0_.version as version4_0_ from publishers_proposals proposals0_ where proposals0_.publisher_id=?
Hibernate: select proposals0_.publisher_id as publisher9_1_, proposals0_.id as id1_, proposals0_.id as id4_0_, proposals0_.additional_info as additional2_4_0_, proposals0_.buy_id as buy3_4_0_, proposals0_.cpm as cpm4_0_, proposals0_.creation_date as creation5_4_0_, proposals0_.last_updated as last6_4_0_, proposals0_.minimum_spend as minimum7_4_0_, proposals0_.proposal_status as proposal8_4_0_, proposals0_.publisher_id as publisher9_4_0_, proposals0_.reveal_num_of_users as reveal10_4_0_, proposals0_.version as version4_0_ from publishers_proposals proposals0_ where proposals0_.publisher_id=?

[http-8080-1] DEBUG org.hibernate.SQL - select mpproposal0_.proposal_id as proposal9_1_, mpproposal0_.id as id1_, mpproposal0_.id as id2_0_, mpproposal0_.budget as budget2_0_, mpproposal0_.comments as comments2_0_, mpproposal0_.cpm as cpm2_0_, mpproposal0_.exclusive_reach as exclusive5_2_0_, mpproposal0_.frequency_cap as frequency6_2_0_, mpproposal0_.impressions as impressi7_2_0_, mpproposal0_.mediaplan_id as mediaplan8_2_0_, mpproposal0_.proposal_id as proposal9_2_0_, mpproposal0_.reach as reach2_0_ from mediaplan_proposals mpproposal0_ where mpproposal0_.proposal_id=?
Hibernate: select mpproposal0_.proposal_id as proposal9_1_, mpproposal0_.id as id1_, mpproposal0_.id as id2_0_, mpproposal0_.budget as budget2_0_, mpproposal0_.comments as comments2_0_, mpproposal0_.cpm as cpm2_0_, mpproposal0_.exclusive_reach as exclusive5_2_0_, mpproposal0_.frequency_cap as frequency6_2_0_, mpproposal0_.impressions as impressi7_2_0_, mpproposal0_.mediaplan_id as mediaplan8_2_0_, mpproposal0_.proposal_id as proposal9_2_0_, mpproposal0_.reach as reach2_0_ from mediaplan_proposals mpproposal0_ where mpproposal0_.proposal_id=?

[http-8080-1] DEBUG org.hibernate.SQL - select adsizes0_.publisher_id as publisher1_1_, adsizes0_.adsize_id as adsize2_1_, adunit1_.id as id1_0_, adunit1_.full_name as full2_1_0_, adunit1_.height as height1_0_, adunit1_.name as name1_0_, adunit1_.type as type1_0_, adunit1_.width as width1_0_ from publishers_adsizes adsizes0_ left outer join ad_units adunit1_ on adsizes0_.adsize_id=adunit1_.id where adsizes0_.publisher_id=?
Hibernate: select adsizes0_.publisher_id as publisher1_1_, adsizes0_.adsize_id as adsize2_1_, adunit1_.id as id1_0_, adunit1_.full_name as full2_1_0_, adunit1_.height as height1_0_, adunit1_.name as name1_0_, adunit1_.type as type1_0_, adunit1_.width as width1_0_ from publishers_adsizes adsizes0_ left outer join ad_units adunit1_ on adsizes0_.adsize_id=adunit1_.id where adsizes0_.publisher_id=?

[http-8080-1] DEBUG org.hibernate.SQL - select publishers0_.adsize_id as adsize2_1_, publishers0_.publisher_id as publisher1_1_, publisher1_.publisher_id as id5_0_, publisher1_1_.name as name5_0_, publisher1_.name as name14_0_ from publishers_adsizes publishers0_ left outer join publishers publisher1_ on publishers0_.publisher_id=publisher1_.publisher_id left outer join accounts publisher1_1_ on publisher1_.publisher_id=publisher1_1_.id where publishers0_.adsize_id=?
Hibernate: select publishers0_.adsize_id as adsize2_1_, publishers0_.publisher_id as publisher1_1_, publisher1_.publisher_id as id5_0_, publisher1_1_.name as name5_0_, publisher1_.name as name14_0_ from publishers_adsizes publishers0_ left outer join publishers publisher1_ on publishers0_.publisher_id=publisher1_.publisher_id left outer join accounts publisher1_1_ on publisher1_.publisher_id=publisher1_1_.id where publishers0_.adsize_id=?

[http-8080-1] DEBUG org.hibernate.SQL - select profiles0_.buy_id as buy1_1_, profiles0_.profile_id as profile2_1_, profile1_.id as id12_0_, profile1_.agency_id as agency2_12_0_, profile1_.name as name12_0_ from buy_profiles profiles0_ left outer join profiles profile1_ on profiles0_.profile_id=profile1_.id where profiles0_.buy_id=?
Hibernate: select profiles0_.buy_id as buy1_1_, profiles0_.profile_id as profile2_1_, profile1_.id as id12_0_, profile1_.agency_id as agency2_12_0_, profile1_.name as name12_0_ from buy_profiles profiles0_ left outer join profiles profile1_ on profiles0_.profile_id=profile1_.id where profiles0_.buy_id=?



[http-8080-1] DEBUG org.hibernate.SQL - select mediaplans0_.buy_id as buy2_1_, mediaplans0_.id as id1_, mediaplans0_.id as id11_0_, mediaplans0_.buy_id as buy2_11_0_, mediaplans0_.is_final as is3_11_0_ from mediaplans mediaplans0_ where mediaplans0_.buy_id=?
Hibernate: select mediaplans0_.buy_id as buy2_1_, mediaplans0_.id as id1_, mediaplans0_.id as id11_0_, mediaplans0_.buy_id as buy2_11_0_, mediaplans0_.is_final as is3_11_0_ from mediaplans mediaplans0_ where mediaplans0_.buy_id=?

[http-8080-1] DEBUG org.hibernate.SQL - select publisherp0_.buy_id as buy3_1_, publisherp0_.id as id1_, publisherp0_.id as id4_0_, publisherp0_.additional_info as additional2_4_0_, publisherp0_.buy_id as buy3_4_0_, publisherp0_.cpm as cpm4_0_, publisherp0_.creation_date as creation5_4_0_, publisherp0_.last_updated as last6_4_0_, publisherp0_.minimum_spend as minimum7_4_0_, publisherp0_.proposal_status as proposal8_4_0_, publisherp0_.publisher_id as publisher9_4_0_, publisherp0_.reveal_num_of_users as reveal10_4_0_, publisherp0_.version as version4_0_ from publishers_proposals publisherp0_ where publisherp0_.buy_id=?
Hibernate: select publisherp0_.buy_id as buy3_1_, publisherp0_.id as id1_, publisherp0_.id as id4_0_, publisherp0_.additional_info as additional2_4_0_, publisherp0_.buy_id as buy3_4_0_, publisherp0_.cpm as cpm4_0_, publisherp0_.creation_date as creation5_4_0_, publisherp0_.last_updated as last6_4_0_, publisherp0_.minimum_spend as minimum7_4_0_, publisherp0_.proposal_status as proposal8_4_0_, publisherp0_.publisher_id as publisher9_4_0_, publisherp0_.reveal_num_of_users as reveal10_4_0_, publisherp0_.version as version4_0_ from publishers_proposals publisherp0_ where publisherp0_.buy_id=?
A: 

Posting my comment as answer: I wonder if this is not a side effect of the XML serialization. Can you confirm this also occurs when no XML serialization is involved?

Pascal Thivent
You are correct, i misunderstood the "lazy" concept. The XML serializer accesses the get and set methods of the collections - making hibernate fetch the whole collection
Noam Nevo