-->
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: Concurrent problem?
PostPosted: Sat Feb 16, 2008 9:49 am 
Newbie

Joined: Thu Feb 14, 2008 4:50 pm
Posts: 3
I have the following situation:
I'm using Spring 2.0.6, hibernate 3.2 and Oracle 10g
There is a table that concentrates a lot of traffic in the application (it is an auditting table) and from time to time it produces a "JDBC can't execute batch update" exception. I believe this is because there is a lot of concurrent access to this table in the database, but I have no proof of that...
The problem may stem from the way Hibernate treats the autogenerated id columns in Oracle. Hibernate issues a select max(id) first, and then uses this number to persist the instance at hand. If there is a high concurrence situacion, I believe is possible for Hibernate to retrieve the same index twice and to try and persist the entity with that id more than once, thus getting the aforementioned error. Again, this is all speculation, I'm to new to know for sure.

But anyway, asuming the problem is concurrence, I want to try the following:
To declare a singleton bean with one private static attribute indexCount accesable only through a public static getCurrentIndex() method that do something like { return indexCount++;}

How safe is this solution, considering many threads asking indexes simultaneously? Is there some built-in mechanism in Spring that can help me achieve something like this? And since we're at it, Spring does anything at all to ensure threadsafe behavior in stateful singleton beans?

I did another solution but i think this is not very well, specially because i don't know why it behave in this way.
I put the generator class like "secuence" and take off the hbm2ddl.auto property in the cfg configuration file and every works well.
Can any body tell me why?

Thanks in advance,
Maykell.


Top
 Profile  
 
 Post subject: Re: Concurrent problem?
PostPosted: Sat Feb 16, 2008 10:42 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
I am not sure but you could also consider using a HI/Lo key generator. Using a in memory counter solution will prevent your application from scaling.



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 16, 2008 10:49 am 
Newbie

Joined: Thu Feb 14, 2008 4:50 pm
Posts: 3
Thank you very much, it was really fast, i did not imagined that you replay me so fast.

ok, i'll tests the solution you propuse me, but i'd like to know about why when i disable the hbm2ddl.auto property in the cfg file and set the id generator class to secuence, everything works well.

Thank you very much once more,
Maykell


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 16, 2008 11:01 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
maykell wrote:
Tbut i'd like to know about why when i disable the hbm2ddl.auto property in the cfg file and set the id generator class to secuence, everything works well.



I don't really know. I would say the sequence thing is a big change since a select count can cause table locks and sequences will not do this. This is the same reason why Hi/Lo would be a solution because every time HB needs to reserve a key region and for the next n ids it will not need to go to database which reduces lock problems. I am not very familiar with oracle but you should be able to trace this by monitoring lock requests and lock timeouts with an Oracle profiling tool.


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 16, 2008 11:04 am 
Newbie

Joined: Thu Feb 14, 2008 4:50 pm
Posts: 3
ok, thank you very much, i will test this rigth now and i will tell you the results.

Thnak you very much.


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.