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.  [ 5 posts ] 
Author Message
 Post subject: Simple entities and batching -- is it possible?
PostPosted: Fri Dec 16, 2005 6:25 pm 
Beginner
Beginner

Joined: Wed Feb 09, 2005 3:27 pm
Posts: 29
I have an entity called Item which has two properties, price and description. No collections or associations exist on this entity. I have a list of 1,000 identifiers for which I want to retrieve the instances. What is the fastest way to do this?

I tried setting the batch size in the mapping for Item to values ranging from 2 to 200, and also setting the hibernate.jdbc.batch_size property, and then calling Session.load(). LockMode.READ was used to ensure that the cache was being bypassed.

When looking at the SQL queries being generated, I see one query for each identifier, i.e. a thousand queries in order to retrieve the thousand instances. I was expecting to see some number close to (1000 / batch size). Also, none of the queries generated have an IN clause.

Is my understanding of how batch sizing works incorrect, i.e. does it only apply to collections? If not, what is the right approach to get this working?

Thanks,

-Kaare


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 17, 2005 8:42 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
The batch size you are updating is for jdbc-batch -
Quote:
A non-zero value enables use of JDBC2 batch updates by Hibernate.
eg. recommended values between 5 and 30


I think the one you want to update is -
hibernate.default_batch_fetch_size


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 4:26 pm 
Beginner
Beginner

Joined: Wed Feb 09, 2005 3:27 pm
Posts: 29
anar wrote:
The batch size you are updating is for jdbc-batch -
Quote:
A non-zero value enables use of JDBC2 batch updates by Hibernate.
eg. recommended values between 5 and 30


I think the one you want to update is -
hibernate.default_batch_fetch_size


Hmm, I added this setting so that I now have:

Code:
<property name="hibernate.default_batch_fetch_size">30</property>
<property name="hibernate.jdbc.batch_size">50</property>
<property name="hibernate.jdbc.fetch_size">25</property>


When I ask for a batch of 60 items I still get 60 SQL statements printed on the console. I verified that the properties are being picked up by the Settings class. The BatchingEntityLoader class is also being invoked.

This is strange. The approach I'm using is this: I compute the identifier for each of the entities being requested, call Session.get() on each of the identifiers, and the finally access the entitties (map instances). The SQL statements being printed are exactly the same (e.g. WHERE item0_.ITEM_ID=?) and do not have an IN clause (e.g. WHERE item0_.ITEM_ID IN (1,2,3).

Any ideas on how to home in on where the problem is?

Thanks,

-Kaare


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 4:31 pm 
Beginner
Beginner

Joined: Wed Feb 09, 2005 3:27 pm
Posts: 29
Sorry, that should be Session.load(), not Session.get().

-Kaare


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 3:10 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
Are you previously running a query for hte identifiers?

I was doing something like this for paging before. is much better idea to use the built in paging functionality than getting ids.

Perhaps you can provide more info on what exactly you are trying to do...I don't think there is a way to do it as a batch if you are simply doing session.load on single entities. Hibernate doesn't know that you might do another session.load. You have to do some sort of collection get. Then the batch size properties will kick in


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.