-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to disable batch processing in Hibernate
PostPosted: Fri Dec 29, 2006 4:35 pm 
Newbie

Joined: Fri Dec 29, 2006 4:19 pm
Posts: 3
Hello friends,

We have a problem with how the batch processing works in one scenerio and would like to disable it. Here is the issue -

1. We begin a transaction.

2. We insert 2 records in table A.

3. Now we run a query on table A (plus few others in a join) that should return the sum of some records in table A including the 2 records entered in step 2.

4. Now with that sum, we try to insert a 3rd record in table A.

5. commit.

The problem is, the INSERT statements are fired only when the "commit" is executed and so the select query in step 3 can't find those 2 and returns incorrect result.

In hibernate.cfg.xml, we have this -

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

We also tried to change the value from 0 to 1, but it seems, the batch processing is always enabled and ignores the batch size.


Hibernate version: 3.2

Name and version of the database you are using: Oracle 10g

Is there a way we can disable the batch processing in this case ? Any help would be greatly appreciated.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 29, 2006 4:55 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Nothing to do with batch processing. It's the flushmode here. just call session.flush() after the second step and you're done.

You should read about the hibernate session. If you want to affect permanently the session object, you can call session.setFlushMode(FlushMode.ALWAYS) => it will send any SQL order to the db without waiting (by default, it is set to FlushMode.AUTO).

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 29, 2006 6:30 pm 
Newbie

Joined: Fri Dec 29, 2006 4:19 pm
Posts: 3
Thanks batmat.

This is what I did -
___________________
session.setFlushMode(FlushMode.ALWAYS);
Transaction tx = session.getTransaction();
tx.begin();

INSERT 1st
INSERT 2nd
...
SELECT SUM() ...
...
INSERT 3rd
....

tx.commit();
___________________

I also turned the show_sql property on so that after each insert, it prints the SQL. But it prints the SQLs only after commit.

I'll try the session.flush() now. Actually we are using a custom framework so Hibernate session object is not used directly in the code, so I was avoiding the session.flush().


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 29, 2006 6:44 pm 
Newbie

Joined: Fri Dec 29, 2006 4:19 pm
Posts: 3
The session.flush() works as you said. For now, we'll add this in the stub code so that for every insert, update and delete, the session is flushed. Thanks batmat. credit++ ;)


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