Announcement Announcement Module
Collapse
No announcement yet.
hic problem about simple Transaction. please help me hic Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • hic problem about simple Transaction. please help me hic

    i just begin with transaction, please help me

    my config file is:


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    ................................... oracle ....
    </bean>

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource"> <ref local="dataSource"/></property>
    </bean>

    <!-- configure JdbcTemplate with the same datasource -->
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" >
    <property name="dataSource" ref="dataSource" />
    </bean>

    <bean id="txProxyTemplate" abstract="false" class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="transactionManager" ref ="transactionManager"/>
    <property name="target" ref ="targetBean"/>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
    </props>
    </property>
    </bean>

    <bean id="targetBean" class="transactionPack.TransactionDaoImpl">
    <property name="jdbcTemplate" ref="jdbcTemplate"/>
    </bean>
    </beans>

    -------------------------------------------------
    code of Class MyDao

    public interface MyDao {
    void update(String nendo);
    void insert(String nendo);
    void delete(String nendo);
    void querySql();
    }
    -------------------------------------------------
    code of class TransactionDaoImpl


    public class TransactionDaoImpl extends JdbcDaoSupport implements MyDao{

    private JdbcTemplate jdbcTemplate = new JdbcTemplate();

    public void delete(){
    getJdbcTemplate().update("DELETE Test WHERE AAA= '2007'");
    }

    public void insert(){
    getJdbcTemplate().execute("INSERT INTO Test (AAA, BBB, CCC, DDD) VALUES('2008', 120, 35, 45)");
    }

    public void querySql() {
    System.out.println(getJdbcTemplate().queryForList( "SELECT * FROM Test "));
    }

    public void update(){
    getJdbcTemplate().update("UPDATE Test SET BBB= '10' AND CCC = '20' DDD = '30' AND WHERE AAA = '2007'");
    }

    }


    ---------------------------------
    main class


    public class MainClass {
    /**
    * @param args
    */
    public static void main(String[] args) throws Exception {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("simpleTransaction. xml");
    MyDao service =(MyDao)ctx.getBean("txProxyTemplate");

    service.delete();// ---> delete Ok

    service.insert(); //--->> throws Exception, cause insert same primary key

    // service.querySql();
    }
    }

    problem is it still delete although Exception happened

    i don't know why . hic please help me.
Working...
X