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.
- what correct transactionattributes update , updatecontext?
- 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
Post a Comment