-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate batch fetches despite FetchType.LAZY
PostPosted: Tue Jun 12, 2012 5:47 am 
Newbie

Joined: Tue Jun 12, 2012 5:36 am
Posts: 1
Hi,

I have an entity, let's call it XRequest, which has a member called RequestgroupXConfig (which is actually a Many-To-Many association table of two IDs, but that doesnt matter).

Code:
@Entity
class XRequest {

   // other members, stuff...
   @ManyToOne
    @Basic(fetch = FetchType.LAZY)
   @JoinColumns({
      @JoinColumn(name="group_id", referencedColumnName="group_id"),
      @JoinColumn(name="config_id", referencedColumnName="config_id")
      })
   private RequestgroupXconfig requestgroupXconfig;

}


Then, I use an HQL statement (following) to query XRequest with a bunch of joins to other tables.
Code:
Query q = em.createQuery("SELECT DISTINCT e, rg, sc, svt, srt, st
            FROM XRequest e
            inner join fetch e.requestgroup rg
            inner join fetch e.someconfig sc
            inner join fetch e.someversionthing svt
            inner join fetch svt.somereleasething srt
            inner join fetch srt.something st
            WHERE e.something != 'whatever'
            order by e.bullshit");
List li = q.getResultList();


Now, this query is executed just fine. But while executing getResultList(), another query happens to pop up on my radar: a query to requestgroupXconfig (which actually is a many-to-many id-association table of "requestgroup" and "someconfig"; one group may have many configs or many groups one config or many groups many configs). I am not using requestgroupXconfig though, not joining it, and I annotated it as lazy fetching - why on earth is that query executed?

(Don't ask me why the requestgroupXconfig is there - it just has to be; not my specs. I can't remove it, I'm not allowed to.)

Thanks,
Chris


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.