-->
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.  [ 9 posts ] 
Author Message
 Post subject: why hibernate batch size setting no work?
PostPosted: Mon Sep 18, 2006 5:01 am 
Newbie

Joined: Mon Aug 21, 2006 9:15 pm
Posts: 17
Hi, I want to use batch inserting in Hibernate.
And I have set property "hibernate.jdbc.batch_size 20" in hibernate configure file.
but when I run the following code:
try
{
Session session = DbFactory.getImportDbFactory().openCurrentSession();
for(int i=0; i<list.size(); i++)
{
session.save(list.get(i));
}
session.flush();
session.clear();
}
catch(Exception ex)
{
throw new DbException(ex.toString());
}


when run this code, list's size is 20.
but when I run this code, I found Hibernate insert 20 times(I set show sql to true, and it means hibernate print 20 insert statements to screen!). it seems bacth setting is useless, why?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 18, 2006 8:58 pm 
Newbie

Joined: Mon Aug 21, 2006 9:15 pm
Posts: 17
I'm so urgent, thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 18, 2006 10:47 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
dont manage session flusing yourself

take out

session.flush();
session.clear();
and try again...

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 1:43 am 
Newbie

Joined: Mon Aug 21, 2006 9:15 pm
Posts: 17
I tried , it seems hibernate still doesn't use batch save. And, I can't omit session.flush and session.clear method, otherwise I 'm afraid it will exhaust computer's memory.
I really don't know why hibernate doesn't use batch save? so strange!


Top
 Profile  
 
 Post subject: Batch save
PostPosted: Tue Sep 19, 2006 2:26 am 
Beginner
Beginner

Joined: Mon Nov 22, 2004 11:21 am
Posts: 42
In order to use batch save the database and the JDBC driver - both - need to support this feature.

What I don't understand is the hype around this feature. Traditional SQL databases support only two forms of INSERTs: INSERT ... VALUES and INSERT ... SELECT. If you really want to put several rows via one SQL statement into a table, you need a (temporary) table to read from. The only advantage I see is to transfer the commands in batches through the network and therefore less response latency times. Please correct me if I'm wrong.

_________________
Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 2:37 am 
Newbie

Joined: Mon Aug 21, 2006 9:15 pm
Posts: 17
here is screen output for hibernate:
14:22:44,727 INFO Environment:479 - Hibernate 3.1
14:22:44,727 INFO Environment:494 - loaded properties from resource hibernate.properties: {hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.max_fetch_depth=1, hibernate.jdbc.use_streams_for_binary=true, hibernate.format_sql=true, hibernate.jdbc.batch_size=20, hibernate.query.substitutions=yes 'Y', no 'N', hibernate.proxool.pool_alias=pool1, hibernate.cache.region_prefix=hibernate.test, hibernate.connection.url=jdbc:hsqldb:., hibernate.show_sql=true, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=1}
14:22:44,742 INFO Environment:524 - using java.io streams to persist binary types
14:22:44,742 INFO Environment:525 - using CGLIB reflection optimizer


And, I think hibernate has read batch configuration. or are some other properties wrong?


Top
 Profile  
 
 Post subject: Re: Batch save
PostPosted: Tue Sep 19, 2006 4:15 am 
Newbie

Joined: Mon Aug 21, 2006 9:15 pm
Posts: 17
gskempes wrote:
In order to use batch save the database and the JDBC driver - both - need to support this feature.

What I don't understand is the hype around this feature. Traditional SQL databases support only two forms of INSERTs: INSERT ... VALUES and INSERT ... SELECT. If you really want to put several rows via one SQL statement into a table, you need a (temporary) table to read from. The only advantage I see is to transfer the commands in batches through the network and therefore less response latency times. Please correct me if I'm wrong.

thanks for your reply.
In fact I'm using ORACLE as the underlying database, which support JDBC's batch operation. (And I think most database should suuport this, otherwise JDBC can't be a standard database access specification).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 19, 2006 5:21 am 
Newbie

Joined: Mon Aug 21, 2006 9:15 pm
Posts: 17
thanks for your help, I have confirmed that hibernate will use batch insert in this situation, but it will print insert statment each time, so this print statment puzzled me, but when I change log from info to debug, it shows Hibernate use batch insert!


Top
 Profile  
 
 Post subject: About JDBC
PostPosted: Tue Sep 19, 2006 5:25 am 
Beginner
Beginner

Joined: Mon Nov 22, 2004 11:21 am
Posts: 42
Don't forget that there are different JDBC driver types (1 to 4) and different versions of the API (1.0 - 3.0). And when it comes to industry standards, Oracle is for sure not the best example for compliance.

Anway, to all others: Are my assumptions in my previous posting correct?

_________________
Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25


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