-->
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.  [ 11 posts ] 
Author Message
 Post subject: how to use batch update feature in the hibernate?
PostPosted: Wed Sep 03, 2003 5:54 am 
Newbie

Joined: Wed Sep 03, 2003 5:50 am
Posts: 8
Hi:
Does anyone konw how to use batch update feature in the hibernate?Please send me a example.Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 6:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You simply set


hibernate.jdbc.batch_size=10


or whatever


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 11:06 pm 
Newbie

Joined: Wed Sep 03, 2003 5:50 am
Posts: 8
O Yes,I did so.But it did not work.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 11:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
perhaps your jdbc driver does not implement batch updates (this is very common)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 1:48 am 
Newbie

Joined: Wed Sep 03, 2003 5:50 am
Posts: 8
Thanks.My JDBC Driver is mysql mysql connector 3.08 stable.And the driver support batch mode.The following is my config file content:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

<session-factory>
<!--hibernate jdbc configuration -->
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=Big5</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.connection.pool_size">10</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.jdbc.batch_size">25</property>
<property name="show_sql">ture</property>
<property name="use_outer_join">true</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<!--hibernate jdbc configuration end -->

<!-- Mapping files -->
<mapping resource="mapping.hbm.xml"/>
<mapping resource="child.hbm.xml"/>
</session-factory>

</hibernate-configuration>

and the test server code is :
public void createParent(Parent parent,int count) throws HibernateException {
for (int i=0;i<count;i++){
session.save(parent);
}
}

test client code is :
public void testCreateParent() throws HibernateException{
application.beginTransaction();
application.createParent(parent,10);
application.endTransaction(true);
}

but the result is just that only a result is inserted.
why?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 1:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ummmmm.


This code would only insert one record even if batch updates are _dis_abled.

If you read the Hibernate documentation, it explains how the Hibernate session-level cache works. You can't save the same instance multiple times and have it somehow transform itself into multiple instances.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 2:11 am 
Newbie

Joined: Wed Sep 03, 2003 5:50 am
Posts: 8
Oh,Thanks."have it somehow transform itself into multiple instances".Could you tell me in detail.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 2:31 am 
Newbie

Joined: Wed Sep 03, 2003 5:50 am
Posts: 8
Excuse me! Is it convenient for you to post me a sample code snippet about batch save(update/delete).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 3:32 am 
Newbie

Joined: Tue Aug 26, 2003 10:17 pm
Posts: 5
Hi,

In your test code you wrote:

for (int i = 0; i < count; i++) {
session.save(parent);
}

since parent's pk field never changes in the loop, you are trying to save the same object (into the same table row) that many times, of course only one row will be saved.

Clarence


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 4:05 am 
Newbie

Joined: Wed Sep 03, 2003 5:50 am
Posts: 8
Oh,The pk is generate by uuid and it is defined in the mapping file.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 27, 2004 5:50 pm 
Beginner
Beginner

Joined: Thu Sep 11, 2003 8:41 am
Posts: 35
Location: Atlanta, GA
just to double check...

If I want to do batch writes to the database all I have to do is set the property in the config file...

<property name="hibernate.jdbc.batch_size">25</property>

I have a few questions about how the batch stuff works.

Does Hibernate store the items you are going to insert/update in the session until it reaches it's batch limit, then write everything?

If the limit is never reached, I assume it does the batch when commit() is called, is that correct?

If I am using the "identity" id generation method and I insert a row with batch enabled, do I have the ability to get the PK from the recently inserted object, even if the batch has not gone off?

Finally, is there a limit to the batch_size or a number that you would suggest not going above?

Thanks!
Chris

_________________
I am the reason spellcheck was created!!!


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