0 Replies Latest reply on Feb 14, 2008 3:09 PM by Maykell Frometa

    Concurrence problem?

    Maykell Frometa Newbie

      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?


      Thanks in advance,
      Maykell.