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: BatchSize and size of IN sets
PostPosted: Wed Nov 24, 2010 11:15 am 
Newbie

Joined: Fri Nov 19, 2010 11:27 am
Posts: 2
I've noticed a strange behavior while using BatchSize/Prefetching on the inverse side (mappedBy) of a OneToMany relation.

Entity A (1) <---> (0..*) Entity B

Code:
class A {
  ...
  @OneToMany(mappedBy = "a", fetch = FetchType.LAZY)
  @BatchSize(size=50)
  public Set<B> bs;
}

class B {
  ...
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "A_FK", nullable = false, unique = false)
  public A a;
}

While iterating over a number of A entities and accessing their "bs", Hibernate (pre-)fetches the "bs" collections lazily.

Case 1: OK
If the number of uninitialized collection proxies equals the defined BatchSize of 50, Hibernate uses only a single query to initialize all 50 proxies as expected.

> select ... where ... in (?, x50)


Case 2: ??
But when the number of uninitialized collection proxies is lower than the defined BatchSize (e.g. 45 proxies), Hibernate suddenly needs 3 queries to initialize all proxies.

> select ... where ... in (?, x23)
> select ... where ... in (?, x11)
> select ... where ... in (?, x11)


My expectation would have been, that Hibernate uses a single query with an IN set of 45 elements instead.
What's the idea of this behavior?

From reading http://docs.jboss.org/hibernate/core/3. ... mance.html "19.1.5. Using batch fetching" I would have expected that the size of the IN sets should be min(#uninitializedProxies, BatchSize).


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.