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 :

AbstractTransactionalSpringContextTests : rollback échoue


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Invité1
    Invité(e)
    Par défaut AbstractTransactionalSpringContextTests : rollback échoue
    Bonjour, j'ai un problème dans l'écriture d'un Test sur Spring en utilisant AbstractTransactionalSpringContextTests.

    Cette classe permet de faire des modification dans les méthodes de Tests qui seront ensuite annulée automatiquement à la fin des tests, ce qui permet par exemple d'éviter qu'un test modifie la base de données.

    Le problème est qu'il m'indique qu'un rollBack a été fait mais qu'au bout du compte (et à la fin de la batterie de Test) je me retrouve avec les modifications toujours présentes dans la BD.

    Si quelqu'un à déjà eu ce problème ou est susceptible de m'aider je l'en remercie.

    Bonne journée !
    Dernière modification par Robin56 ; 06/08/2013 à 13h23. Motif: Ajout du préfixe

  2. #2
    Membre confirmé
    Inscrit en
    Octobre 2002
    Messages
    108
    Détails du profil
    Informations forums :
    Inscription : Octobre 2002
    Messages : 108
    Par défaut
    As tu de messages d'erreur lors de rollback? Sinon, tu as peut-être fait des commits quelques parts dans le code?

  3. #3
    Membre confirmé Avatar de tnodev
    Profil pro
    SSSSS
    Inscrit en
    Mai 2005
    Messages
    182
    Détails du profil
    Informations personnelles :
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : SSSSS

    Informations forums :
    Inscription : Mai 2005
    Messages : 182
    Par défaut
    Essaye dans ton fichier de config JDBC

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    defaultAutoCommit=false
    car moi les test à l'aide de AbstractTransactionalSpringContextTests fonctionnent correctement...

  4. #4
    Invité1
    Invité(e)
    Par défaut
    Attention, accrochez vous.

    Il n'y a pas d'erreur et non je ne commite pas dans mes tests

    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
     
    INFO - Began transaction (1): transaction manager [org.springframework.jdbc.datasource.DataSourceTransactionManager@1d64c37]; default rollback = true
    DEBUG - Executing prepared SQL update
    DEBUG - Executing prepared SQL statement [insert into personne(nomPersonne, prenomPersonne, agePersonne) values(?, ?, ?)]
    DEBUG - Fetching JDBC Connection from DataSource
    DEBUG - Creating new JDBC Connection to [jdbc:mysql://localhost/spring]
    DEBUG - Registering transaction synchronization for JDBC Connection
    DEBUG - Bound value [org.springframework.jdbc.datasource.ConnectionHolder@b9b538] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@25d2b2] to thread [main]
    DEBUG - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@b9b538] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@25d2b2] bound to thread [main]
    DEBUG - Setting SQL statement parameter value: column index 1, parameter value [stemmer], value class [java.lang.String], SQL type unknown
    DEBUG - Setting SQL statement parameter value: column index 2, parameter value [laurent], value class [java.lang.String], SQL type unknown
    DEBUG - Setting SQL statement parameter value: column index 3, parameter value [23], value class [java.lang.Integer], SQL type unknown
    DEBUG - SQL update affected 1 rows
    DEBUG - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@b9b538] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@25d2b2] bound to thread [main]
    DEBUG - Executing prepared SQL update
    DEBUG - Executing prepared SQL statement [insert into personne(nomPersonne, prenomPersonne, agePersonne) values(?, ?, ?)]
    DEBUG - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@b9b538] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@25d2b2] bound to thread [main]
    DEBUG - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@b9b538] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@25d2b2] bound to thread [main]
    DEBUG - Setting SQL statement parameter value: column index 1, parameter value [wrobel], value class [java.lang.String], SQL type unknown
    DEBUG - Setting SQL statement parameter value: column index 2, parameter value [marc], value class [java.lang.String], SQL type unknown
    DEBUG - Setting SQL statement parameter value: column index 3, parameter value [23], value class [java.lang.Integer], SQL type unknown
    DEBUG - SQL update affected 1 rows
    DEBUG - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@b9b538] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@25d2b2] bound to thread [main]
    DEBUG - Triggering beforeCompletion synchronization
    DEBUG - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@b9b538] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@25d2b2] from thread [main]
    DEBUG - Returning JDBC Connection to DataSource
    DEBUG - Initiating transaction rollback
    DEBUG - Rolling back JDBC transaction on Connection [com.mysql.jdbc.Connection@1595f51]
    DEBUG - Triggering afterCompletion synchronization
    DEBUG - Clearing transaction synchronization
    DEBUG - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@9e29fb] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@110fe28] from thread [main]
    DEBUG - Releasing JDBC Connection [com.mysql.jdbc.Connection@1595f51] after transaction
    DEBUG - Returning JDBC Connection to DataSource
    INFO - Rolled back transaction after test execution
    INFO - Closing org.springframework.context.support.GenericApplicationContext@1431340: display name [org.springframework.context.support.GenericApplicationContext@1431340]; startup date [Wed Apr 18 10:58:29 CEST 2007]; root of context hierarchy
    DEBUG - Publishing event in context [org.springframework.context.support.GenericApplicationContext@1431340]: org.springframework.context.event.ContextClosedEvent[source=org.springframework.context.support.GenericApplicationContext@1431340: display name [org.springframework.context.support.GenericApplicationContext@1431340]; startup date [Wed Apr 18 10:58:29 CEST 2007]; root of context hierarchy]
    INFO - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@10a3b24: defining beans [personneDAO,dataSource,txManager]; root of factory hierarchy
    Et voici ma classe de Test :

    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
     
     
    package spring.tests;
     
    import org.springframework.test.AbstractTransactionalSpringContextTests;
     
    import spring.dao.IPersonneDAO;
    import spring.entity.Personne;
    import spring.utils.Utils;
     
    public class Test extends AbstractTransactionalSpringContextTests {
     
    	private IPersonneDAO personneDAO;
    	private Utils utils;
    	private Personne personne;
     
    	public TestPersonneFixed() {
    		utils = Utils.getInstance("spring/resources/spring.cfg.xml");
    		personneDAO = utils.getService("personneDAO", IPersonneDAO.class);
    	}
     
    	@Override
    	protected String[] getConfigLocations() {
    		return new String[]{"spring/resources/spring.cfg.xml"};
    	}
     
    	@Override
    	protected void onSetUpBeforeTransaction() throws Exception {
    		personne = new Personne();
    		super.onSetUpBeforeTransaction();
    	}
     
    	public void testBatch() {
    		//mes test d'insertions puis suppression dans la bases
    		//....
    	}
     
    	@Override
    	protected void onTearDownAfterTransaction() throws Exception {
    		super.onTearDownAfterTransaction();
    		endTransaction();
    	}
    }
    Sinon c'est Spring qui se charge de la Transaction donc il n'y a pas de fichier de configuration.

    Encore merci.
    Dernière modification par Invité1 ; 18/04/2007 à 11h29. Motif: Rajout d'informations

  5. #5
    Membre confirmé
    Inscrit en
    Octobre 2002
    Messages
    108
    Détails du profil
    Informations forums :
    Inscription : Octobre 2002
    Messages : 108
    Par défaut
    dans le log, on voit bien que Spring rollback la transaction après le test.

    Tu surcharges la méthode onTearDownAfterTransaction() et appelles explicitement endTransaction. C'est fait exprès?

    Sinon, c'est peut-être la version de mysql qui ne supporte pas la transaction???

Discussions similaires

  1. Que se passe-t-il en interne si un ROLLBACK plante ?
    Par jack554 dans le forum Administration
    Réponses: 4
    Dernier message: 07/04/2004, 12h55
  2. Rollback ne marche pas avec interbase
    Par Tsimplice dans le forum Bases de données
    Réponses: 2
    Dernier message: 09/03/2004, 08h39
  3. Le rollback explose au moment du FETCH d'un Curseur
    Par Krashtest dans le forum Administration
    Réponses: 10
    Dernier message: 18/08/2003, 09h46
  4. commit et rollback....?
    Par The_Nail dans le forum MS SQL Server
    Réponses: 6
    Dernier message: 06/06/2003, 14h36
  5. [VB6]ADODB Command, recuperer l'info d'un RollBack
    Par Mouse dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 19/05/2003, 16h26

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