1 of 1 people found this helpful
are you using persistence right?
If you are using persistance you can dispose the session and load it back when you are sure that the thread that was using the session will not use it anymore.
Yeah thats right.I got your point.
But in my case the starting of a process and completion of it happens parallely.
And when i do so as u said. i'm getting this hibernate exception due to optimistic lock.
javax.persistence.OptimisticLockException: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [org.drools.persistence.info.SessionInfo#1]
and im looking for a way to clear this exception.
How do you usually solve a problem when you have 2 or more threads against 1 database that is locking?
I think that's the answer to your question.. sorry to answer with another question
For starting the process, the ksession associated with the taskhandler should be alive.
And by the same time during the completion of the task the ksession should be alive.
As both these shares the same taskhandler i couldnt dispose the ksession.
Hence i thought of having seperate taskhandlers one for starting a process and other for completing a task.
Thats in where i got that optimistic lock exception.
1. Cant i dispose the ksession with shared taskhandler.?
2. If i gotto use seperate taskhandlers, How to correct this exception.?
You can load the session and add a new instance of the task handler for the newly hydrated session, you don't need to share the WorkItemHandler between the two.