Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: transaction sychronization

  1. #1
    Join Date
    Nov 2004
    Posts
    26

    Default transaction sychronization

    I do not want any of my db updates to be part of a transaction. Each one should commit as it is performed.
    My problem is that this is not happening. Nothing is commited till the end.
    I was able to solve this problem by shutting off transaction sychronization however I get an IllegalStateException (I must have sychronization) when the second db update is attempted.

    <bean id="ReportEngine" parent="myTransactionManager" >
    <property name="target">
    <bean class="net.idt.ReportEngine.Report.ReportEngine">
    <property name="queryGroupDao">
    <ref local="QueryGroupDao"/>
    </property>
    <property name="reportEngineParamDao">
    <ref local="ReportEngineParamDao"/>
    </property>
    </bean>
    </property>
    </bean>


    <bean id="mySessionFactory"
    class="org.springframework.orm.hibernate.LocalSess ionFactoryBean">
    <property name="mappingLocations">
    <list>
    <value>/code/config/QueryGroup.hbm.xml</value>
    <value>/code/config/Query.hbm.xml</value>
    <value>/code/config/ReportSource.hbm.xml</value>
    <value>/code/config/FTPQueryAction.hbm.xml</value>
    <value>/code/config/EmailQueryAction.hbm.xml</value>
    <value>/code/config/FTPHost.hbm.xml</value>
    <value>/code/config/EmailAddress.hbm.xml</value>
    <value>/code/config/GroupEmailInfo.hbm.xml</value>
    <value>/code/config/ReportEngineParam.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">net.sf.hibernate.dialect.O racle9Dialect</prop>
    </props>
    </property>
    <property name="dataSource">
    <ref bean="dataSource"/>
    </property>
    <property name="lobHandler">
    <ref local="oracleLobHandler"/>
    </property>
    </bean>

    <!-- Database LOB Handling -->
    <bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc .SimpleNativeJdbcExtractor" />

    <bean id="oracleLobHandler" class="org.springframework.jdbc.support.lob.Oracle LobHandler">
    <property name="nativeJdbcExtractor">
    <ref local="nativeJdbcExtractor"/>
    </property>
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName">
    <value>oracle.jdbc.driver.OracleDriver</value>
    </property>
    <property name="url">
    <value>jdbc:oracle:thin:@ora-il:1521:tomcatdv</value>
    <!--<value>jdbc:oracle:thin:@scrooge.corp.idt.net:1521 :csh2go</value>-->
    </property>
    <property name="username">
    <value>tre_app</value>
    </property>
    <property name="password">
    <value>tre_app</value>
    </property>
    </bean>


    <!-- Hibernate Transaction Manager -->
    <bean id="transactionManager" class="org.springframework.orm.hibernate.Hibernate TransactionManager">
    <property name="sessionFactory">
    <ref bean="mySessionFactory"/>
    </property>
    <property name="transactionSynchronization">
    <value>1</value>
    </property>
    </bean>

    <bean id="myTransactionManager" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager"><ref local="transactionManager"/></property>
    <property name="target"><ref bean="ReportGenerator"/></property>
    <property name="proxyTargetClass"><value>true</value></property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_SUPPORTS</prop>
    </props>
    </property>
    </bean>

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Then you don't need transactions - you can stop using the TransactionManager and it's overhead. Moreover you can turn on auto-commit on your datasource which will make the updates hit the database once they are fired.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3
    Join Date
    Nov 2004
    Posts
    26

    Default

    If I don't use transactions I get

    java.lang.IllegalStateException: Active Spring transaction synchronization or jtaTransactionManager on LocalSessionFactoryBean plus active JTA transaction required

  4. #4
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Transactions are required by Spring lob support (for resource cleanup). The problem I see with your configuration is the transactionSynchronization value - why did you change it?

    P.S. posting a bigger stack trace makes diagnosis easier.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  5. #5
    Join Date
    Nov 2004
    Posts
    26

    Default

    when i set transactionsychronization to 1 then the first db update commits right away. The problem is that the second db update will give me

    java.lang.IllegalStateException: Active Spring transaction synchronization or jtaTransactionManager on LocalSessionFactoryBean plus active JTA transaction required
    at org.springframework.orm.hibernate.support.Abstract LobType.nullSafeSet(AbstractLobType.java:169)
    at net.sf.hibernate.type.CustomType.nullSafeSet(Custo mType.java:118)
    at net.sf.hibernate.persister.EntityPersister.dehydra te(EntityPersister.java:387)
    at net.sf.hibernate.persister.EntityPersister.update( EntityPersister.java:642)
    at net.sf.hibernate.persister.EntityPersister.update( EntityPersister.java:621)
    at net.sf.hibernate.impl.ScheduledUpdate.execute(Sche duledUpdate.java:52)
    at net.sf.hibernate.impl.SessionImpl.execute(SessionI mpl.java:2449)
    at net.sf.hibernate.impl.SessionImpl.executeAll(Sessi onImpl.java:2435)
    at net.sf.hibernate.impl.SessionImpl.execute(SessionI mpl.java:2393)
    at net.sf.hibernate.impl.SessionImpl.flush(SessionImp l.java:2261)
    at org.springframework.orm.hibernate.HibernateAccesso r.flushIfNecessary(HibernateAccessor.java:214)
    at org.springframework.orm.hibernate.HibernateTemplat e.execute(HibernateTemplate.java:229)
    at org.springframework.orm.hibernate.HibernateTemplat e.saveOrUpdate(HibernateTemplate.java:387)
    at net.idt.ReportEngine.dao.QueryGroupDao.saveQueryGr oup(QueryGroupDao.java:57)
    at net.idt.ReportEngine.Report.ReportEngine.runGroup( ReportEngine.java:84)
    at net.idt.ReportEngine.Report.ReportEngine.Run(Repor tEngine.java:74)
    at net.idt.ReportEngine.Report.ReportEngine$$FastClas sByCGLIB$$2a0a241e.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy. java:149)
    at org.springframework.aop.framework.Cglib2AopProxy$C glibMethodInvocation.invokeJoinpoint(Cglib2AopProx y.java:676)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :121)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:56)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :143)
    at org.springframework.aop.framework.Cglib2AopProxy$D ynamicAdvisedInterceptor.intercept(Cglib2AopProxy. java:619)
    at net.idt.ReportEngine.Report.ReportEngine$$Enhancer ByCGLIB$$6fa1b16c.Run(<generated>)
    at net.idt.ReportEngine.Report.ReportEngine.main(Repo rtEngine.java:122)



    So... obviously this is not the solution. so how do I get each db update to commit automatically??

  6. #6
    Join Date
    Nov 2004
    Posts
    26

    Default

    as a continuation from last post....
    here's my code. maybe it will be helpfull

    public void Run(){

    if(reNeedsToRun()) {//*************the method reNeedsToRun will update the db*************
    logger.info("ReportEngine Starting Up.");
    Calendar now = Calendar.getInstance();
    List groups = queryGroupDao.listQueryGroups();
    Iterator qgIt = groups.iterator();
    Timestamp tNow= new Timestamp(now.getTimeInMillis());


    while(qgIt.hasNext()){
    Query_Group query_group = (Query_Group) qgIt.next();
    Timestamp lastRunDt = query_group.getLast_run_dte();
    double intervAsDbl = Double.parseDouble(query_group.getInterval());
    int intervInMinutes = (int)(intervAsDbl * 60.0); //multiply by 60 to get in minutes
    Calendar nextRun = Calendar.getInstance();
    if(lastRunDt == null){
    nextRun.add(Calendar.MINUTE,-10); // set it back 10 minutes so it will run
    }
    else{
    nextRun.setTime(lastRunDt);
    nextRun.add(Calendar.MINUTE,intervInMinutes);
    }
    if(now.getTimeInMillis() >= nextRun.getTimeInMillis() ){
    runGroup(query_group, tNow); //**********the method runGroup will update the db. *************
    }
    }
    }

    }

  7. #7
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Use the normal transactionSynchronization value and try other transaction attributes (like NOT_SUPPORTED). If this fails turn auto-commit on, on your datasource.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  8. #8
    Join Date
    Nov 2004
    Posts
    26

    Default

    I tried PROPAGATION_NOT_SUPPORTED with the normal transactionSynchronization value and it still did not commit right away. It is acting as if it's in a transaction.

    Is this a bug in Spring- that I need to use transactions when using lobs but cannot shut off the transaction??

  9. #9
    Join Date
    Nov 2004
    Posts
    26

    Default

    also i tried turning autocommit on and it still doesn't work

  10. #10
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Is this a bug in Spring- that I need to use transactions when using lobs but cannot shut off the transaction??
    No, as I said its purpose is to do resource cleanup. I advice you to look at the sources and see if there are any other parameters which you can play with.
    It is acting as if it's in a transaction.
    Turn on logging and see what is going on and why the db is hit. Btw, an important thing - do you use HB flush() to force the commit to the db ?
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •