I'm using an EJB with @scheduled annotation to loop over all my context entities every 10 secs. All Contexts entities are unrelated to each other and therefore should create new transactions for their update method:
@Stateless
public class UpdateService {
@EJB
ContextDao contextDao;
@Schedule(second = "*/10", minute = "*", hour = "*")
public void update() {
for(ContextEntity context : contextDao.findAllContexts()) {
updateContext(context);
}
}
public void updateContext(ContextEntity context) {
// load data from db
// update some stuff
// save back to db
}
}
Now I wanna have an single transactions for the updateContext method. So if I get any error in one ContextEntity, only this transaction should be rolled back and not the whole loop.
- What are the correct TransactionAttributes for update and updateContext?
- Do I have to use a different EJB for the updateContext method?
Thanks