I have a Hibernate Entity in my code. i would fetch that and based on the value of one of the properties ,say “isProcessed” , go on and :
- change value of “isProcessed” to “Yes” (the property that i checked)
- add some task to a DelayedExecutor.
in my performance test, i have found that if i hammer the function,a classic dirty read scenario happens and i add too many tasks to the Executor that all of them would be executed. i can’t use checking the equality of the objects in the Queue based on anything , i mean java would just execute all of them which are added.
how can i use hibernate’s dirty object stuff to be able to check “isProcessed” before adding the task to executor? would it work?
hope that i have been expressive enough.
If you can do all of your queries to dispatch your tasks using the same Session, you can probably patch something together. The caveat is that you have to understand how hibernate’s caching mechanisms (yes, that’s plural) work. The first-level cache that is associated with the Session is going to be the key here. Also, it’s important to know that executing a query and hydrating objects will not look into and return objects from the first-level cache…the right hand is not talking to the left hand.
So, to accomplish what you’re trying to do (assuming you can keep using the same Session…if you can’t do this, then I think you’re out of luck) you can do the following:
By calling get, you’ll be sure to get the object from the first-level cache…where all the dirty objects pending flush are held.
For background, this is an extremely well-written and helpful document about hibernate caching.