committing stored procedure

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

committing stored procedure

Mr.Squirrel
Hi there,

How to make a commit when calling a stored procedure which make an insert :
This commit doesn't work :

public void insererCiv1() {
        try {
                       
        Adresse autreAdresse = new Adresse();
        autreAdresse.setCodEtudiant("09F643X");
        autreAdresse.setCodTypAdresse("1");
        autreAdresse.setTel("0240281365");
        autreAdresse.setComplement("c2");
        autreAdresse.setNum("1");
        autreAdresse.setVoie("2");
        autreAdresse.setLocalite("paris");
        autreAdresse.setCp("75000");
        autreAdresse.setVille("paris");
        autreAdresse.setPays("100");
       
  this.getSqlMapClient().startTransaction();
  this.getSqlMapClient().queryForObject("pAdresse", autreAdresse); // call stored procedure which make an insert
  this.getSqlMapClient().commitTransaction();

   } catch (SQLException e) {
        System.out.println(e);
   } finally{
           try {
               this.getSqlMapClient().endTransaction();
            } catch (SQLException e) {
            }
        }
        }

sqlMap.xml (stored procedure making an insert)
...
<procedure id="pAdresse" parameterMap="adresseParamMap">
    { call pbw_adresse.MajAdresse(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) }
</procedure>

SpringConfiguration.xml :
...
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
                destroy-method="close">
                <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
                <property name="url" value="jdbc:oracle:thin:@oolong:1521:geotest" />
                <property name="username" value="***" />
                <property name="password" value="***" />
                <property name="validationQuery" value="SELECT 1 FROM DUAL" />
                <property name="testOnBorrow" value="true" />
                <property name="defaultAutoCommit" value="false" />
        </bean>

        <bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
                <property name="sqlMapClient">
                        <bean class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
                                <property name="configLocation">
                                        <value>classpath:fr/univNantes/sig/swelPrimo/ibatis/SqlMapConfig.xml
                                        </value>
                                </property>
                                <property name="dataSource">
                                        <ref bean="dataSource" />
                                </property>
                                <property name="transactionConfigClass">
                                        <value>com.ibatis.sqlmap.engine.transaction.jdbc.JdbcTransactionConfig</value>
                                </property>                               
                        </bean>
                </property>
        </bean>
       
Thanks

François
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: committing stored procedure

Clinton Begin
Because you're calling a "query", iBATIS doesn't realize you're actually updating, so it won't commit by default.

Set your transactionManager config in your configuration XML file to commitRequired="true".

Check the user guide for more.  And make sure to switch to the MyBatis lists for future questions.

Cheers,
Clinton

On Fri, Jun 4, 2010 at 3:23 AM, Mr.Squirrel <[hidden email]> wrote:

Hi there,

How to make a commit when calling a stored procedure which make an insert :
This commit doesn't work :

public void insererCiv1() {
       try {

       Adresse autreAdresse = new Adresse();
       autreAdresse.setCodEtudiant("09F643X");
       autreAdresse.setCodTypAdresse("1");
       autreAdresse.setTel("0240281365");
       autreAdresse.setComplement("c2");
       autreAdresse.setNum("1");
       autreAdresse.setVoie("2");
       autreAdresse.setLocalite("paris");
       autreAdresse.setCp("75000");
       autreAdresse.setVille("paris");
       autreAdresse.setPays("100");

 this.getSqlMapClient().startTransaction();
 this.getSqlMapClient().queryForObject("pAdresse", autreAdresse); // call
stored procedure which make an insert
 this.getSqlMapClient().commitTransaction();

  } catch (SQLException e) {
               System.out.println(e);
  } finally{
          try {
              this.getSqlMapClient().endTransaction();
           } catch (SQLException e) {
           }
       }
       }

sqlMap.xml (stored procedure making an insert)
...
<procedure id="pAdresse" parameterMap="adresseParamMap">
   { call pbw_adresse.MajAdresse(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) }
</procedure>

SpringConfiguration.xml :
...
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
               destroy-method="close">
               <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"
/>
               <property name="url" value="jdbc:oracle:thin:@oolong:1521:geotest" />
               <property name="username" value="***" />
               <property name="password" value="***" />
               <property name="validationQuery" value="SELECT 1 FROM DUAL" />
               <property name="testOnBorrow" value="true" />
               <property name="defaultAutoCommit" value="false" />
       </bean>

       <bean id="sqlMapClientTemplate"
class="org.springframework.orm.ibatis.SqlMapClientTemplate">
               <property name="sqlMapClient">
                       <bean class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
                               <property name="configLocation">
                                       <value>classpath:fr/univNantes/sig/swelPrimo/ibatis/SqlMapConfig.xml
                                       </value>
                               </property>
                               <property name="dataSource">
                                       <ref bean="dataSource" />
                               </property>
                               <property name="transactionConfigClass">

<value>com.ibatis.sqlmap.engine.transaction.jdbc.JdbcTransactionConfig</value>
                               </property>
                       </bean>
               </property>
       </bean>

Thanks

François
--
View this message in context: http://old.nabble.com/committing-stored-procedure-tp28777607p28777607.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: committing stored procedure

Mr.Squirrel
ok thank you Clinton !

I have solved the probleme by adding a fake update before the call of my procedure.
then, iBATIS understand that it's an update transaction.

I will also try your solution as soon as possible
Loading...