Anayonkar Shivalkar wrote:So, if I understand correctly,
1) If same instance calls the method via different threads, then the method should act like synchronized.
2) If different instance calls the method via different threads, then the method need not be acting like synchronized.
Well, it is quite easy if this is the case. If you still find it difficult, then just take a look at synchronization chapter from any descent Java book.
I hope this helps.
Anayonkar Shivalkar wrote:Hi sankalp suryawanshi,
Welcome to CodeRanch!
In your question, where does serialization come in picture? All I see is you are fetching from and updating the value to DB.
If you want that update operation to be synchronized, then you must ensure that no two concurrent requests should go to DB.
Hint : The method (or the relevant code) must be synchronized across the objects (i.e. no matter which object is calling it). If you synchronize it on 'this', then it won't work.
Pranav Pal wrote:I have found that the reason why I was getting exception was that I had mapped a primitive property (active - boolean) to a nullable column (ISACTIVE). Since primitives cannot be null, one cannot map it to a nullable ccolumn. I was not getting the same excpetion for isPaidUser because the type declared for isPaidUser was Boolean (Wrapper class) and not boolean (primitive).
Thank you Mark and Jaikiran for your help