java ee - Loop inside @Schedule with new transactions -


this question exact duplicate of:

i'm using ejb @scheduled annotation loop on context entities every 10 secs. contexts entities unrelated each other , therefore should create new transactions 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 db          // update stuff          // save db     } } 

now wanna have single transactions updatecontext method. if error in 1 contextentity, transaction should rolled , not whole loop.

  1. what correct transactionattributes update , updatecontext?
  2. do have use different ejb updatecontext method?

thanks

i presume want call updatecontext not update inside loop.

the update-method defined has attribute transactionattributetype.required default , can left way.

the updatecontext-method should annotated transactionattributetype.requires_new, but... if want call in transaction-context, must use

@resource sessioncontext sessioncontext; 

and fetch businessinterface sessioncontext call updatecontext

as example @ singletonejb see method methodcallusingsessioncontext


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -