Try to use StaleObjectStateException to prevent current modification. It worked however but broke my existing code.
I am doing two thing within one method, say
foo(params...){
...
//do a save, so as I can get the id to be used in anotherMethod()
save(ccCase);
//
anotherMethod(ccCase.getId());
...
}
The problem is within the anotherMethod() I am doing a findByExample() call.
Hibernate does a insert for ccCase, and within the anotherMethod, it does an update for ccCase again, which I am not quite sure why. So the StaleObjectStateException was thrown even this is really within the same method, not modified by another user. I understand if I comment the save() method, when the findByExample() was called within the anothrerMethod, hibernate will do the save as well, since hibernate will flush before query sometime. But I do need the save so I can get access to the id it generated.
What do I need to do the prevent this StaleObjectStateException from happening here?
Thanks,
|