[jboss-user] [JBoss Seam] - Re: FlushMode=MANUAL -- not immediately commited to db?

dreuzel do-not-reply at jboss.com
Wed Feb 13 05:20:51 EST 2008


I've  got about the same  problem as you ,
and  found the sollution for  your  part
 handling BMT 

a)  components.xml   switch of  transactions (see seam manual)
 
  |    <core:init debug="@debug@" jndi-pattern="@jndiPattern@" transaction-management-enabled="false"/>   <!-- transaction-management-enabled="false" -->
  |    <!--    <transaction:no-transaction />   -->    <transaction:no-transaction /> 
  |    <core:manager concurrent-request-timeout="500" 
  |                  conversation-timeout="99000000" 
  |   
b)   is  use following  class i extend  to my  EJB
i'm still trying  out  the code, so any remarks are welcome

my problem is  that  after  some 300 transactions (5minutes/processing for 1 request) all of a sudden  it  loses the transaction  and whatever  I do I'm dead . I'm still trying to solve that one 




  | 
  | 
  | //@Stateless 
  | //@Startup
  | //@Name("BMT")
  | //@TransactionManagement(TransactionManagementType.BEAN) 
  | public class BMT {
  | @Logger private Log log;
  | //@Scope(ScopeType.APPLICATION)
  | static int txncount=0;
  | @PersistenceContext (type=EXTENDED) private EntityManager em;//do not use @in em
  | //@in em would work just fine if you would call entityManager.joinTransaction() 
  | // in your method before you use the EntityManager. 
  | // Of course the @Injected EM will not join the transaction automatically 
  | // because the transaction is started AFTER injection, when the method is called. 
  | //
  | @Resource  private UserTransaction userTransaction; 
  | public String process(String xml)    throws Exception {return null;}
  | public String copy(StatementsDB sta) throws Exception {return null;} 
  | public String txs(String argument,StatementsDB sta) throws Exception
  | {boolean rollback=true;
  | 
  |  String result=null;
  |       int ier=0;
  |        if (txncount<1) {txncount=100;
  |                         int tmo=this.setSessuionTimeout(30);//do not timeout while operations are active
  |                         boolean seso=isNewSession();}
  |            --txncount;
  |       if (!em.isOpen()) 
  |     	  log.info("Em  persitence manager  not open any more !!!");
  |       try{  em.joinTransaction(); }catch (Exception er)
  |           {ER(er,"em join the transaction  transaction ");throw(er);} //after practicaly 5 minutes   we die here 
  | 
  |       
  |       try{  ier=userTransaction.getStatus(); }catch (Exception er) {ER(er,"get status transaction ");}
  |       //set transaction timeout
  |       try{  userTransaction.setTransactionTimeout(100000); }catch (Exception er) {ER(er,"transaction timeout  ");}
  |       if (ier!=6) log.info("Status  transaction different "+ier);
  | try{	
  |     try {// what is  the  ejbcontext ????
  |     	//EJB             userTransaction  = EJBContext.getUserTransaction( );//EJBclassical way 
  |         userTransaction= org.jboss.seam.util.EJB.getEJBContext().getUserTransaction();//EJB
  | //SEAMEJB    	 if (  userTransaction.isNoTransaction())//SEAMEJB if(transaction.getStatus() == Status.STATUS_NO_TRANSACTION){
  | //SEAMEJB    		 {   userTransaction= org.jboss.seam.util.EJB.getEJBContext().getUserTransaction();//SEAMEJB
  | //SEAMEJB    		 }
  |     	  userTransaction.begin(); // etc
  |           //  em.joinTransaction();
  |         } catch(Exception er) {ER(er,"Begin transaction");}
  |         String res=null;
  |         if (argument!=null) 
  |             res = process(argument);
  |         if (sta!=null)    
  |         	res=copy(sta);
  |     try {
  |     	userTransaction.commit(); // etc
  |     	rollback=false;//all is successful   kill any possible rollback
  |     	result=res;//only if successfull commited the result is passed 
  |         }  catch(Exception er) {ER(er,"Commit transaction");}
  |     
  |   } catch(Exception er) {ER(er,"Transaction");}
  |   finally
  |   {  try {
  | //SEAMEJB if (!userTransaction.isCommitted()) {userTransaction.rollback();NewTransaction();}//auto detect commitment 
  | //SEAMEJB else 
  |     	  if (rollback) {userTransaction.rollback();
  | 	                     //get a  new transaction
  |                          NewTransaction();//Em.gettransaction not for JTA BMT em.getTransaction();//
  | 	                    }
  |          } catch (Exception er)
  |                  { String errmsg=er.getClass().getSimpleName() +" err: "+ er.getMessage();
  |                    if(errmsg.indexOf("NullPointer")>-1 || errmsg.indexOf("OutOfBounds")>0) log.fatal("[transaction BMT ] Rollback  failed  "+ errmsg,er);
  |                    else  log.error("[transaction BMT ] Rollback  failed  "+ errmsg );
  |                  }
  |   }//finaly 
  |   return result;
  | }
  | public int  setSessuionTimeout(int minutes)
  | {    if (minutes <1)minutes=1;
  |   int tmo=0;
  |   try {
  |       Object  obj =ServletContexts.instance().getRequest();//null?
  |       if (obj!=null)obj=ServletContexts.getInstance().getRequest().getSession();
  |      if (obj!=null) tmo=ServletContexts.instance().getRequest().getSession().getMaxInactiveInterval();
  |      if (obj!=null) ServletContexts.instance().getRequest().getSession().setMaxInactiveInterval(minutes*60);
  |      if (obj!=null) return tmo;
  |      //	 int tmo=
  | //		     org.jboss.seam.web.ServletContexts.instance().getRequest().getSession().getMaxInactiveInterval();
  | //			 org.jboss.seam.web.ServletContexts.instance().getRequest().getSession().setMaxInactiveInterval(minutes*60);
  | 			 return minutes;
  |   } catch (Exception er)
  |   { String errmsg=er.getClass().getSimpleName() +" err: "+ er.getMessage();
  |   if(errmsg.indexOf("NullPointer")>-1 || errmsg.indexOf("OutOfBounds")>0) log.fatal("ServletContext   error "+ errmsg+" time:"+tmo+"/"+ minutes,er);
  |   else  log.error("[ServletContext error  set timeout   "+ errmsg +" time:"+tmo+"/"+ minutes );}
  |     return 0;
  | }
  | 
  | 
  | public boolean isNewSession()
  | 
  | {     try{
  | 	    Object  obj =ServletContexts.instance().getRequest();//null
  | 
  |        if (obj!=null)obj=ServletContexts.instance().getRequest().getSession();
  |      if (obj!=null) return ServletContexts.instance().getRequest().getSession().isNew();
  | 
  | //	return org.jboss.seam.web.ServletContexts.instance().getRequest().getSession().isNew();
  | 
  | } catch (Exception er)
  | { String errmsg=er.getClass().getSimpleName() +" err: "+ er.getMessage();
  | if(errmsg.indexOf("NullPointer")>-1 || errmsg.indexOf("OutOfBounds")>0) log.fatal("new session   error "+ errmsg,er);
  | else  log.error("[ServletContext error  set timeout   "+ errmsg  );}
  | 
  |      return true;
  | }
  | private void NewTransaction()
  | {
  | 	log.error("I urgently  want a new transaction, I lost the  old  one  in a rollback");
  | 	try{
  | //	em.joinTransaction();//test 
  | 	} catch (Exception er){ER(er,"JOIN TRANSACTION RECOVER ");}
  | 	
  | }
  | private void ER(Exception er,String mes)
  |     {String errmsg=er.getClass().getSimpleName() +" err: "+ er.getMessage();
  |      if(errmsg.indexOf("NullPointer")>-1 || errmsg.indexOf("OutOfBounds")>0) log.error(mes+"  "+ errmsg,er);
  |      else  log.error(mes+"  "+ errmsg);
  | }
  | 

It's  not essential to do the  Join the TXN  with em but that way  my  problem is detected  prior  to executing  my process...



any comment is welcome  of coarse.
     

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4129060#4129060

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4129060



More information about the jboss-user mailing list