Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Transaction unable to Rollback

  1. #11
    Join Date
    May 2007
    Posts
    9

    Default

    Karldmoore, what do you mean by case issue, i am unable to understand? What should i do now, can you please suggest?

  2. #12
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Sorry I meant the case of the bean name, as in upper case and lower case letters. The exception says it can't find 'DInterface' and your bean is called 'dInterface'. Hence I think you need to change your lookup to 'dInterface'.
    No bean named 'DInterface' is defined
    Code:
    <bean id="dInterface" class="Do.DImpl"/>
    Last edited by karldmoore; Aug 30th, 2007 at 05:49 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #13
    Join Date
    May 2007
    Posts
    9

    Default

    Thanks Karldmoore,
    I was looking at the example given on following link
    http://www.springframework.org/docs/...ansaction.html
    and in this example it is using interface "FooService" as "fooService" in ApplicationContext.xml so i changed my interface name to "dInterface". However, that problem is resolved now after changing "dInterface" to "DInterface" but still transaction is unable to rollback. Following is the out that i am getting

    Code:
    Jun 1, 2007 6:30:04 PM org.springframework.context.support.AbstractApplicationContext refresh
    
    INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@e: display name [org.springframework.context.support.ClassPathXmlApplicationContext@e]; startup date [Fri Jun 01 18:30:04 GMT+05:00 2007]; root of context hierarchy
    
    Jun 1, 2007 6:30:04 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    
    INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
    
    Jun 1, 2007 6:30:06 PM org.springframework.context.support.AbstractApplicationContext refresh
    
    INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@e]: org.springframework.beans.factory.support.DefaultListableBeanFactory@29
    
    Jun 1, 2007 6:30:06 PM org.springframework.context.support.AbstractApplicationContext$BeanPostProcessorChecker postProcessAfterInitialization
    
    INFO: Bean 'org.springframework.aop.config.internalAutoProxyCreator' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
    
    Jun 1, 2007 6:30:06 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@29: defining beans [DInterface,dDataSource ,txAdvice,org.springframework.aop.config.internalAutoProxyCreator,dInterfaceOperation,org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor,dataSource,txManager]; root of factory hierarchy
    
    Jun 1, 2007 6:30:06 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
    
    INFO: Loaded JDBC driver: oracle.jdbc.driver.OracleDriver
    
    i am here
    
    in else
    
    in else
    
    in if
    
    in if
    
    in if
    
    Yes got return values
    
    Please Rollback the transaction..........

    According to my opinion my Stored Procedure inserts data in a table and returns Out Params, i am getting those outparams which i shouldn't get because i am rolling back the transaction after calling procedure. Now my ApplicationContext looks like this:-

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           xsi:schemaLocation="
           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
    
    <beans>
    
    <!-- this is the service object that we want to make transactional -->
    <bean id="dInterface" class="Do.DImpl"/>
    
    <!-- the transactional advice (i.e. what 'happens'; see the <aop:advisor/> bean below) -->
      <tx:advice id="txAdvice" transaction-manager="txManager">
        <!-- the transactional semantics... -->
        <tx:attributes>
          <!-- other methods use the default transaction settings (see below) -->
          <tx:method name="procWithStringOnly" rollback-for="UnsupportedOperationException"/>
        </tx:attributes>
      </tx:advice>
    
    <!-- ensure that the above transactional advice runs for any execution
          of an operation defined by the FooService interface -->
      <aop:config>
        <aop:pointcut id="dInterfaceOperation" expression="execution(* Do.DInterface.*(..))"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="dInterfaceOperation"/>
      </aop:config>
    
    <bean id="dDataSource " class="Test.DDataSource">
       <property name="dataSource">
         <ref local="dataSource"></ref>
       </property>
    </bean>
    
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close">
      <property name="driverClassName">
        <value>oracle.jdbc.driver.OracleDriver</value>
      </property>
      <property name="url">
        <value>jdbc:oracle:thin:@192.168.0.211:1521:ONCDB1</value>
      </property>
      <property name="username">
        <value>Test</value>
      </property>
      <property name="password">
        <value>Test</value>
      </property>
    </bean>
    
    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
       <property name="dataSource" ref="dataSource"/>
    </bean>
    </beans>
    Note: Change is in Bold i.e. added rollback-for attribute

  4. #14
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Is there a method called procWithStringOnly on DImpl? Does DImpl implement DInterface? Is it possible to see the code you're running?
    Last edited by karldmoore; Aug 30th, 2007 at 05:49 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  5. #15
    Join Date
    May 2007
    Posts
    9

    Default

    Hi Karldmoore,
    Here is my code:-

    My Interface
    Code:
    package Do;
    import org.springframework.context.ApplicationContext;
    
    public interface DInterface
    {
    public void procWithStringOnly();
    public void setAppContext(ApplicationContext apctx);
    public void TestTransaction();
    }
    My Implementation Class
    Code:
    package Do;
    import java.sql.Types;
    import java.util.Hashtable;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlAp plicationContext;
    import org.springframework.jdbc.core.SqlOutParameter;
    import org.springframework.jdbc.core.SqlParameter;
    import Test.OStoredProcedure;
    
    public class DImpl implements DInterface
    {
    ApplicationContext applicationContext = null;
    public void procWithStringOnly()
    {
    Hashtable procParamsTypes = new Hashtable();
    Hashtable procParams = new Hashtable();
    String strVal = "1»155»1»'1001100000'»'TALAL'»'AHMED'»''»'123 ROAD SIDE'»'07009'»'NJ'»'CEDAR GROVE'»''»'M'»'(434)324-3242'»''»'1966/02/16'»''»''»84430561»0»0»'2007/05/26'»3»'1210'»'1215'»''»''»84430561»'1444'»'3621'»' 1'»0»1";
    String loginType = "1";
    
    procParamsTypes.put("1", new SqlParameter("strVal", Types.VARCHAR));
    procParamsTypes.put("2", new SqlParameter("loginType", Types.VARCHAR));
    procParamsTypes.put("3", new SqlOutParameter("returnArray", Types.VARCHAR));
    procParamsTypes.put("4", new SqlOutParameter("patientID", Types.VARCHAR));
    procParamsTypes.put("5", new SqlOutParameter("slotAllocationID", Types.VARCHAR)); 
    procParams.put("1", strVal);
    procParams.put("2", loginType);
    OStoredProcedure osp = new OStoredProcedure();
    osp.executeStoredProcedure("SCHL_APPOINTMENTS.inse rt", procParamsTypes, procParams, applicationContext);
    try
    {
    this.TestTransaction(); 
    }
    catch(UnsupportedOperationException uoe)
    {
    System.out.println("Please Rollback the transaction..........");
    }
    
    }
    
    public void TestTransaction()
    {
    throw new UnsupportedOperationException();
    }
    public void setAppContext(ApplicationContext apctx)
    {
    this.applicationContext = apctx;
    }
    
    public static void main(String[] str1)
    {
    ApplicationContext appContext = new ClassPathXmlApplicationContext (
    new String [] { "applicationContext.xml" } ); 
    
    DInterface di = (DInterface) appContext.getBean("DInterface");
    di.setAppContext(appContext);
    di.procWithStringOnly(); 
    }
    
    }

    My OStoredProcedure Class
    Code:
    package Test;
    import java.sql.CallableStatement;
    import java.sql.Types;
    import java.util.HashMap;
    import java.util.Hashtable;
    import java.util.Map;
    import oracle.jdbc.OracleTypes;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlAp plicationContext;
    import org.springframework.jdbc.core.SqlOutParameter;
    import org.springframework.jdbc.core.SqlParameter;
    import org.springframework.jdbc.object.StoredProcedure;
    
    public class OStoredProcedure extends StoredProcedure
    {
    
    
    public OStoredProcedure()
    { 
    }
    
    public void executeStoredProcedure(String procName, Hashtable procParamsTypes, Hashtable procParams, ApplicationContext appContext)
    { 
    Map inParams = new HashMap(2); 
    try
    {
    setDataSource(((DDataSource)appContext.getBean("dD ataSource")).getDataSoutce()); 
    setSql(procName); 
    }
    catch(Exception ex)
    {
    ex.printStackTrace();
    } 
    for(int i=1; i<=procParamsTypes.size();i++)
    {
    try
    {
    Class cSqlOutParameter = Class.forName("org.springframework.jdbc.core.SqlOu tParameter");
    Class cSqlParameter = Class.forName("org.springframework.jdbc.core.SqlPa rameter");
    if(cSqlOutParameter.isInstance(procParamsTypes.get (i+"")))
    {
    System.out.println("in if");
    declareParameter((SqlOutParameter) procParamsTypes.get(i+"")); 
    }
    else if(cSqlParameter.isInstance(procParamsTypes.get(i+ "")))
    {
    System.out.println("in else");
    declareParameter((SqlParameter) procParamsTypes.get(i+""));
    inParams.put(((SqlParameter) procParamsTypes.get(i+"")).getName(), procParams.get(i+"").toString());
    } 
    }
    catch(ClassNotFoundException cnfe)
    {
    cnfe.printStackTrace();
    } 
    }
    compile();
    
    Map outParams = execute(inParams); 
    if (outParams.size() > 0) {
    String[] str1 = null;
    System.out.println("Yes got return values");
    } else {
    System.out.println("have nothing");
    } 
    } 
    }

  6. #16
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I think the problem here is that your service method catches the exception and then swallows it. To rollback the transaction declaratively you'd need to let it pass through the transaction boundary e.g. rethrow the exception after logging or just don't catch it in the first place. As UnsupportedOperationException is unchecked you also don't have to explicity delcare a rollback rule.
    http://www.springframework.org/docs/...decl-explained
    Last edited by karldmoore; Aug 30th, 2007 at 05:48 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

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