-->
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: inner join fetch still leads to extra query
PostPosted: Wed Mar 24, 2010 6:11 pm 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
Hi,

I have an entity
Offer with two referenced entities A and B
Code:
        @OneToOne(optional = false, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
   @JoinColumn(name = "FK_AID",nullable=false,updatable=false)
   @IndexedEmbedded
   public A getA() {
      return a;
   }

   @OneToOne(optional = false, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
   @JoinColumn(name = "FK_BID",nullable=false,updatable=false)
   @IndexedEmbedded
   public B getB() {
      return b;   
  }

When I run the following query, Hibernate executes an extra query for each A and B in stead of just retrieving all data in one go. The extra queries are executed as part of the list() action.

Code:
String qry = "from Offer o "
            + "inner join fetch o.a a "
            + "inner join fetch o.b "
      qry += " where a.validFrom <= current_date and a.validUntil >= current_date "
            + "and a.disabled = false and o.active = true "
            + "and a.activated = true ";
      Query query = getHibernateTemplate().getSessionFactory()
            .getCurrentSession().createQuery(qry);
      query.setFirstResult(start);
      query.setMaxResults(max);
      return query.list();


I don't get why A and B require an extra query since they are supposedly eagerly fetched by specifying inner join fetch.

Any ideas on why this might be happening?

Kind regards,

Marc


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.