Tuesday, October 27, 2015

Corrective Action for Hibernate


An undo functionality is necessary for all systems. When customer calls for a bad data
that he created he is not willing to cancel it. He wants to delete all evidences
from system.

Think we are creating a purchase order. We can cancel order. But user wants to delete
created products ,shipment and payment terms...

So what can we do is refer to article for "Event Loggging".
We need to find the session id of main object.(Purchase Order)
And find all the objects related with it.
Then delete.

Right?
What about updates done to Purchase Order?

So we need a field on our beans that creates and updates our beans.
Open a field concatenate every session id that affected your bean.
1st item will be creator sessionid,others will be updaters.

Then a query delete all related items will be like :

SessionId Concatanted : 12,34,46
12 : creator session 34,46 updaters

delete from tableX where sessionid in (12,34,46);
delete from tableY where sessionid in (12,34,46);
delete from tableZ where sessionid in (12,34,46);

Code for this part is easy if you read other thread.
It is important to get the idea.

Of course one can do this with JDBC. We only need to have unique number(or string)
for every transaction we are doing.

Here I say session usually. Because our sessions are single transaction and atomic.
So while reading you can realize to call this transaction.It depends on your model.

No comments:

Post a Comment