-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: transaction problems Bean managed transaction synchronisati
PostPosted: Tue Jan 22, 2008 8:25 am 
Newbie

Joined: Tue Nov 15, 2005 7:20 am
Posts: 17
i run JBoss 4.2.2Ga -Seam 2.0.0.ga but that should not matter


my intention:
i need to update thousands of independent records in sheduled environment.

For efficiency reasons I need to do that in a big loop ( set of loops)
also because the underlying info is externaly organised like that.

Code:
process

Connect  external
loop
   update record
   if (fails)
      Rollback this ONLY RECORD WITHOUT ANY IMPACT
      ON THE REST OF THE ENVIRONMENT
handle  next


It is very important the overall process is not aborted on any individual error.
(this is what is happening in the actual case with a fail rate on 1 on 1000 this means
I never get never nothingthing done !!!!)

at this time I use following code to handle the transaction

as I'm working in a seam environment
I switched to manual transaction handling
and I'm bouncing/fighting against JTA CONTAINER - BEAN managed transactions



Code:
@Name("loopscan")
@TransactionManagement(TransactionManagementType.BEAN)         //kill container management
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)  //suspend  all active  container transactions
public class BatchTransactions
{
//    @Logger
   private Log log;
//    @In ("#{entityManager}")
   public        EntityManager em;//allow for  db ACCESS   
   Session ses=null;//session indicator
   String env="Init";
//   org.hibernate.Transaction txn=null;//hibernate transaction
public BatchTransactions() {}
public void initTransaction()
{
}
public Exception sequence()
{
    Exception errcod=null;
    org.hibernate.Transaction txn=null;//
    boolean   rollback=false;
    //reset  timeout
    try { env="Timeout";
          org.jboss.seam.transaction.Transaction.instance().setTransactionTimeout(60*60*10000000);
        } catch (Exception er)
                           {errcod=er;
                            String errmsg=er.getClass().getSimpleName() +" err: "+ er.getMessage();
                            log.error(env+" Modifying timeout failed "+ errmsg);
                           }
   // seam timeout    
    try { env ="seam timeout";              
        Transaction.instance().setTransactionTimeout(60*60*10000000);} catch (Exception er)
          {errcod=er;
           String errmsg=er.getClass().getSimpleName() +" err: "+ er.getMessage();
             log.error(env+" Modifying Seam  timeout failed "+ errmsg);
             }
    //
    //connect to session
    //
        env="setup";
        ses=(Session) em.getDelegate();//get  the session

    //
    //   transaction with own error handling
    //
    try { env="Begin";// Begin the transaction ?          
         txn=ses.getTransaction();
         if(!txn.isActive())
                                txn.begin();//       txn=ses.beginTransaction(); **********************
                                // txn.setTimeout(500000);
        } catch (Exception er )
                     {errcod=er;
                        String errmsg=er.getClass().getSimpleName() +" err: "+ er.getMessage();
                        log.error(env+" starting transaction failed "+ errmsg);
                   }
    try {env="execute ";  //ececution process
        errcod=Execute();//do the  DB operations
       try {//flush the  info to other users
               ses.flush();
              } catch (Exception er )
                               {errcod=er;rollback=true;
                                 String errmsg=er.getClass().getSimpleName() +" err: "+ er.getMessage();
                                 log.error("Flush "+env+" Commiting transaction failed "+ errmsg);
                                }

       try {//commit the information
           txn.commit();
          } catch (Exception er )
                                {errcod=er;rollback=true;
                                  String errmsg=er.getClass().getSimpleName() +" err: "+ er.getMessage();
                                  if (errmsg.indexOf("NullPointerException")>-1)
                                     log.error("Commit "+env+" Commit nullpointer exception failed "+ errmsg,er);
                                   else log.error(env+" Commiting transaction failed "+ errmsg);
                                 }
       
     } catch( GenericJDBCException er)
               {String errmsg=er.getClass().getSimpleName() +" err: "+ er.getMessage();rollback=true;
//               if (errmsg.indexOf("Cannot open connection")>-1)
//                     {   if  (!em.isOpen()) log.info("Em session still open !");
//                        try {if (ses==null) {ses=(Session) em.getDelegate();}//get  the session
//                                txn=ses.beginTransaction();     
              log.error(env+" Cannot open connection "+ errmsg,er);
               }
       catch (Exception er) {FatalStatus();errcod=er;rollback=true;
                            String errmsg=er.getClass().getSimpleName() +" err: "+ er.getMessage();
                             if (errmsg.indexOf("NullPointerException")>-1)
                                             log.error(env+" nullpointer exception failed "+ errmsg,er);
                                else log.error(env+" overall transaction error "+ errmsg);
                          }
          if (rollback)
              try {//rollback cover
                  txn.rollback();
                  } catch (Exception er)
                                       {errcod=er;
                                        String errmsg=er.getClass().getSimpleName() +" err: "+ er.getMessage();
                                        log.error("Rollback "+env+" Rollback transaction failed "+ errmsg +" From "+ errmsg);
                                       }
          //
          //   detect losing the session
          //
        if (ses==null)
        { if (!(em.isOpen()))  log.info("em session closed !");
        }
   return errcod;
   
}
/*
*/
public void      TxnSts(String env)  {this.env=env;}
public Exception Execute() throws Exception  {return null;};
public void      FatalStatus() {};
}
{

As you can see most of the code is error trapping and reporting

It fails at the BEGIN transaction
stating : TransactionException err: Could not register synchronization for container transaction

The default for the bean is set to BEAN transactions
but still it considers it a Container transaction


any suggestions would be more then welcome

_________________
XML way to go


Top
 Profile  
 
 Post subject: Re: transaction problems Bean managed transaction synchroni
PostPosted: Tue Jan 22, 2008 11:14 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
How is hibernate configured in terms of transaction? Is it supposed to work with a JTA transaction manager? If so (and I do believe it does), you will need to get an instance of user transaction and begin a transaction before calling begin transaction on the hibernate side.

However, this is the typical use case of MDBs? Can't you switch to MDBs? You could also define an EJB with a method that requires a new transaction each time and call the ejb method in the loop.



Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 05, 2008 9:56 am 
Newbie

Joined: Tue Nov 15, 2005 7:20 am
Posts: 17
sory for later delay, but I'm so disapointed in the transactions I
tried to move to something else... to run back into the transaction problem.

I'm using seam 2.0.1GA
with managed transactions completely disabled
(can not commit myself, and tons of problems ....

I hope I'm using JTA but do not want Container management to interfere with my simple transaction behaviour

Pesistence.xml states as follows
Code:
  <persistence-unit name="jobscan"    transaction-type="JTA">   
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <!--  <jta-data-source>java:/jobscanDatasource</jta-data-source>   -->
      <jta-data-source>java:/DevelopmentDS</jta-data-source>

      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
    <!-- <property name="hibernate.hbm2ddl.auto" value="validate"/> validate -->
         <property name="hibernate.hbm2ddl.auto" value="validate"/>
         <property name="hibernate.show_sql?" value="true"/>
         <property name="hibernate.format_sql?" value="true"/>
         <property name="jboss.entity.manager.factory.jndi.name" value="java:/httpscanEntityManagerFactory"/>
     <!-- These are the default for JBoss EJB3, but not for HEM: -->
         <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
          <property name="hibernate.jdbc.batch_size" value="20"/>
<!--     <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/>
         <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JbossTransactionManagerLookup"/>  -->
         <!-- use a file system based index -->


component.xml
Code:
  <core:init debug="@debug@" jndi-pattern="@jndiPattern@"  transaction-management-enabled="false" />
                  conversation-timeout="12000000"    -->     
   <core:manager concurrent-request-timeout="5000000"
                 conversation-timeout="200000000"
                 conversation-id-parameter="cid"/>
    <transaction:no-transaction />         
   <persistence:managed-persistence-context name="entityManager"
                                     auto-create="true"
                      persistence-unit-jndi-name="java:/jobscanEntityManagerFactory"/>

   
</components>


i get the entity manager from Seam using injection
and I delegate a separate session

please critizize my approach , I'm realy getting desparate



[/code]

_________________
XML way to go


Top
 Profile  
 
 Post subject: Need urgent help with transaction management
PostPosted: Tue Feb 05, 2008 10:56 am 
Newbie

Joined: Tue Nov 15, 2005 7:20 am
Posts: 17
I'm a newbee if you want in hibernate transactions and I'm getting NOWHERE.
I realy need help

I'm using seam 2.0.1.GA but seam wants to manage all transactions for me
within my applicatio n I need to ACCEPT or REFUSE ALL and this is UNACCEPTABLE FOR ME

what I WANT TO DO is
Code:

LOOP

       BEGIN TRANSACTION
             DO what I NEED with my database
       COMMIT or ROLLBACK  ( ONLY  THIS TRANSACTION)
       But in any CASE  CONTINUE with the rest of the loop
NEXT:


Seam seamingly can not handle that, since it wants the full controll
over the transactions, it adds an overall transaction that times out
and or falls over the rollback and I am DEAD.

For this reason I judged it is needed to KILL all SEAM INTERVENTION
The persistance.xml still indicates JTA and JTATransactions.
Code:
pesristence:
  <persistence-unit name="httpscan"    transaction-type="JTA">   
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/DDDDDS</jta-data-source>

      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
         <property name="hibernate.hbm2ddl.auto" value="validate"/>
         <property name="hibernate.show_sql?" value="true"/>
         <property name="hibernate.format_sql?" value="true"/>
         <property name="jboss.entity.manager.factory.jndi.name" value="java:/scanEntityManagerFactory"/>
     <!-- These are the default for JBoss EJB3, but not for HEM: -->
         <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
          <property name="hibernate.jdbc.batch_size" value="20"/>
<!--     <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.JTATransactionFactory"/>
         <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JbossTransactionManagerLookup"/>  -->
Components:

   <core:init debug="@debug@" jndi-pattern="@jndiPattern@"  transaction-management-enabled="false" />
   <core:manager concurrent-request-timeout="5000000"
                 conversation-timeout="200000000"
                 conversation-id-parameter="cid"/>
    <transaction:no-transaction />         
   <persistence:managed-persistence-context name="entityManager"
                                     auto-create="true"
                      persistence-unit-jndi-name="java:/scanEntityManagerFactory"/>




now I've the hard Job of setting things up again


I assume I have no container transaction management
and I see at least 3 different ways to use transactions and transaction defintions..


A) I assume I can still use the incected entityManager from seam (CAN I????)
at least I do not need to use JNDI as well

I have an entitymanager but I do not think I can access entity managerFactory
B) CAN I use transactions, directly handling queries& updates with the entityManger


Code:
      setupTransaction however I need to do it ...
      em.createQuery(SQL)....
     commit transaction...


I want , if possible to know how I can setup the transactionFactory so I
can define a transaction, Ive tried but I get all kinds of complains
to much to state here.

What do I need ?
A transaction factory ???
A transaction getting from somewhere
A transaction begin if htat is not the same as above


what I want to do
is stated in the beginning
I need to creat different SEparate transaction contexts that I can rollback or commit
without stopping the loop, or put any punischment on the next transaction in the loop.
C) The seam manual seems to indicate I can not use the entityManager as stated in B
is this true ???? or am I mistaken
D) Seam seams to insinuate I need to delegate to a session
A'm troubled here since what ias the use of having a session at this stage
using the session the Hibernate Calls (queries )are changing format so I guess
I'm not using JTA any more but plain Hibernate right ????

E) in any case I tried it as well but without any real luck.

As I create the session, i can get a transaction and begin a transaction.
I never found out what the differnce was (setup/initiate transaction ,,, versus the begin
possible , but I get troubled with
Code:
TransactionException err: Could not register synchronization for container transaction

I thought using delegation I got rid of the container Transaction.
as You can see I'm in a mess now.


D) is there a way to find out what to do next
eventualy an example on how to setup the transaction system starting from seam
(as I use JNDI, I get into a simmular mess anyhow)
I'm fully blocked at this stage and getting more and more confused,
can anyone please give me a hint to get out of this mess


Thanks in advance

_________________
XML way to go


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.