IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

Spring @transactional ne fait pas de rollback


Sujet :

Spring Java

  1. #1
    Membre à l'essai
    Développeur informatique
    Inscrit en
    Mars 2009
    Messages
    39
    Détails du profil
    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2009
    Messages : 39
    Points : 23
    Points
    23
    Par défaut Spring @transactional ne fait pas de rollback
    Bonjour tout le monde,
    j'utilise Spring pour mes transactions,sauf que lorsque j'ai des exceptions,je n'ai pas de rollback qui est effectué.Voici mon code.

    spring-database.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="maDataSource">
            <property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
            <property name="url" value="jdbc:oracle:thin:@monserveur:1521:MONDEV"/>
            <property name="username" value="MABASE"/>
            <property name="password" value="MABASE"/>
            <property name="testOnBorrow" value="true"/>
            <property name="validationQuery" value="SELECT 1 FROM DUAL"/>
            <property name="maxActive" value="40"/>
            <property name="maxIdle" value="20"/>
            <property name="minIdle" value="5"/>
            <property name="maxWait" value="60000"/>
            <property name="timeBetweenEvictionRunsMillis" value="900000"/>
            <property name="numTestsPerEvictionRun" value="5"/>
            <property name="removeAbandoned" value="true"/>
            <property name="removeAbandonedTimeout" value="30"/>
            <property name="logAbandoned" value="true"/>
        </bean>
    spring-context.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
     
    <?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:context="http://www.springframework.org/schema/context"
      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.5.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-2.5.xsd
                        http://www.springframework.org/schema/tx 
                        http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" >
     
      <context:annotation-config />
     
      <bean class = "fr.sib.digor.spring.extension.AnnotationTransactionAttributeSourceReplacerPostProcessor" />
     
      <bean id="maSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
     
        <property name="dataSource" ref="maDataSource" />
     
        <property name="configLocations">
          <list>
            <value>classpath*:hibernateSIPSDM.cfg.xml</value>
          </list>
        </property>
     
        <property name="hibernateProperties">
          <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
            <prop key="hibernate.show_sql">false</prop>
          </props>
        </property>
     
      </bean>
     
      <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="maSessionFactory" />
        <qualifier value="txManager" />
      </bean>
     
      <tx:annotation-driven />
     
    </beans>
    spring-services.xml

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
    <?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:tx="http://www.springframework.org/schema/tx"
         xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
    	   xmlns:aop="http://www.springframework.org/schema/aop"
         xmlns:context="http://www.springframework.org/schema/context"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    	   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    	   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
         http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
         http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.0.xsd">
     
      <bean id="namedJdbcTemplate" class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
    	<constructor-arg ref="maDataSource"/>
      </bean>
     
      <aop:aspectj-autoproxy/>
     
    </beans>

    Mon service:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
     
    @Service
    public class MonService {
     
     
      @Autowired
      protected MonDAO monDAO;
     
      @Transactional(value="txManager", rollbackFor={Exception.class})
      public void serviceAppelant(String param) throws Exception{
        try {
          monDAO.updateSex(param);
        } catch (Exception up) {
          throw up;
        }
      }
    }

    Mon DAO
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
     
    @Repository
    public class MonDAO {
      @Autowired
      private NamedParameterJdbcTemplate namedJdbcTemplate;
     
      public void updateSex(String param){
        try {
          SqlParameterSource namedParameters = new MapSqlParameterSource(
              "param", param);
          namedJdbcTemplate.update(SQL_TEMPLATE_UPDATE, namedParameters);
     
          //Je provoque une exception
          namedJdbcTemplate.update("MAUVAISE_REQUETE", namedParameters);
        } catch (Exception e) {
          throw e;
        }
      }
    }
    Ma méthode de TU
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
     @Test
      public void update() throws Exception{
          monService.serviceAppelant("1289");
      }
    Une exception est lancée,sauf que le rollback n'est jamais fait.J'ai essayé de mettre
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <property name="defaultAutoCommit" value="false"/>
    Cependant dans ce cas la transaction n'est jamais committée.

    Merci d'avance de votre aide.

  2. #2
    Membre à l'essai
    Développeur informatique
    Inscrit en
    Mars 2009
    Messages
    39
    Détails du profil
    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Mars 2009
    Messages : 39
    Points : 23
    Points
    23
    Par défaut Résolu
    Excusez moi,j'ai résolu le problème, j'utilisais une mauvaise datasource.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [2008R2] Pourquoi la transaction ne fait pas de rollback ?
    Par Kropernic dans le forum Développement
    Réponses: 8
    Dernier message: 01/02/2015, 11h41
  2. Transactions : pas de rollback après une exception levée
    Par if_zen dans le forum Glassfish et Payara
    Réponses: 7
    Dernier message: 22/04/2011, 10h31
  3. [PDO] rollback ne se fait pas sur la totalité de la transaction
    Par Alexdezark dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 02/08/2010, 13h26
  4. [Data] rollback sur transaction ne semble pas fonctionner
    Par willoi dans le forum Spring
    Réponses: 3
    Dernier message: 22/04/2008, 12h39
  5. [SQL Server 8] le join ne se fait pas
    Par Baquardie dans le forum Langage SQL
    Réponses: 10
    Dernier message: 29/07/2004, 14h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo