-
1. Re: Disappearing data...
jobor Sep 25, 2004 4:50 PM (in response to akhammon)You can put the processing of a single entity bean in a single method with a transaction attribute with e.g. RequiresNew. Call the method from another method with a loop. If the single method fails the transaction of the single method is rolled back.
If your loop and single method are in the same bean your new transaction does not work when you do a direct call. Call the single method on the EJBObject like:
MyLocalEJB localEjb = (MyLocalEJB) sessionContext.getEJBLocalObject();
for (Iterator i = things.iterator(); i.hasNext();) {
try {
localEjb.singleMethod();
} catch (Exception e) {
// correct something
}
}
Johan -
2. Re: Disappearing data...
akhammon Sep 29, 2004 7:00 AM (in response to akhammon)Right On,
Thanks so much...
Your suggestion worked like a charm. Although, I had to make another correction to handle the exception, which I will explain below, your suggestion ensures that if anything goes wrong I don't lose all the work I already did, Thanks again.
To implement jobor's suggestion, I did exactly what he said to do, this meant I had to change the private method called in the loop to public and expose it on the local interface of my session bean with a RequiresNew transaction attribute, this worked to ensure that each iterationof the loop is a unit of complete work, instead of the entire process of iterating throught the loop being the unit of work.
The other thing was, I also had to handle the NoSuchObjectLocalException which was the root of the problem in the first place, so I created an wrapper method on the entity that called the abstract accessor method. It handles the NoSuchobjectLocalException by returning null to the caller method.
Believe it or not, these changes dramatically sped up the iteration of the loop. I was nicely supprised as I was under the impression that all of these new transactions would have the opposite effect.
Thanks Again, JBoss Rules.
-Keene