-->
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.  [ 3 posts ] 
Author Message
 Post subject: Extra fetch queries executed in many-to-one
PostPosted: Thu Nov 04, 2004 7:35 pm 
Newbie

Joined: Thu Nov 04, 2004 7:23 pm
Posts: 2
Here's an excerpt of my code (I only copied the bits I think are relevant)
Code:
/**
* @hibernate.class table="bid"
*/
public class Bid  {

   private int id;

   String title;
   
   User user = new User();
   
   Item item = new Item();
   
   /**
    * @hibernate.many-to-one column="user_id"
    */
   public User getUser() {
      return user;
   }
      
   /**
    * @hibernate.many-to-one column="item_id"
    */
   public Item getItem() {
      return item;
   }
}

/**
* @hibernate.class table="item"
*/
public class Item {
   
   private int id;

   private String name;
}

when I do a query like this:

Code:
"from Bid where user_id = :userId"


The query runs fine and the results are the expected ones. Still, I noticed that there are eight extra SQL's that fetch Items. I am not touching the items after the query, just calling bid.getTitle().
Initially I thought that it is fetching all the associated items but there are 13 corresponding items so it's fetching less.
Could anyone tell me what is the reason for the 8 requests?[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 05, 2004 3:56 am 
Newbie

Joined: Thu Nov 04, 2004 7:23 pm
Posts: 2
I found out why it is fetching 8 instead of 13: there are only 8 distinct values. Now I have to find out how to stop the fetching alltogether.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 07, 2004 7:59 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
Try using this mapping instead:
Code:
/**
* @hibernate.class table="item" lazy="true"
*/
public class Item {
   
   private int id;

   private String name;
}


I think the most recent XDoclet has support for the class-level lazy attribute. Otherwise, use the proxy attribute (or there's an XDolcet patch you can apply).

_________________
Cheers,
Shorn.


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

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.