Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
[b]Hibernate version: 3.0[/b]
[b]MySql 4.1.8[/b]
[b]The generated SQL (show_sql=false):[/b]
Hi I am developing an application using Hibernate 3.0 and MySql 4.1.8. This application is to be accessed simultaneously(concurrent access) by multiple users.
These multiple users access and updates certain common rows from the database in different sessions.
So, the problem is that application is accessing same bussiness object(database identity) in different session concurrently. Hence the JVM identity of the two instances will be actually different. This causes inconsistencies while updating certain fields for that business object, like say count.
Let a given database row is aceessed concurrently by two users,
User A creates Obj1 in session1 and User B creates Obj2 in session2 . Both Obj1 and Obj2 represent the same row in the database. Let at the time of loading initial count is 45 for both.
Let it is incremented when user finishes and updates this Object with database. As there are two accesses to this object hence it should increase by two.
count should increase by two but actually it is only increasing by 1.
Is there a standard way to avoid this in hibernate. So, that I can use same business object(database identity) in different sessions but still the results should be consistent. Or I have to deal with this at application level.
I can solve this by making a class which contains a static synchronized method used for every access that will write to any object in the database. But, this will serailize whole the update operation on the database. Is there any other way out.