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 :

transation required problème de rollback


Sujet :

Spring Java

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    185
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 185
    Points : 109
    Points
    109
    Par défaut transation required problème de rollback
    Bonjour
    je suis newbie en spring 2.5 et j'essaie de tester le commit et le rollback des transaction, pour cela j'essaie de forcer une exception pour voir s'il y aura commit ou rollback de transaction avec different type de propagation ...


    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
     
    @Transactional
    	public void purchase(String isbn, String username) throws Exception{
    		Book book = bookDao.executeSingleQuery(
    				ConstantQueries.BOOK_FIND_BY_ISBN, new Object[] { isbn });
    		BookStock bookStock = bookStockDao.executeSingleQuery(
    				ConstantQueries.STOCK_FIND_BY_ISBN, new Object[] { isbn });
    		Account account = accountDao
    				.executeSingleQuery(ConstantQueries.ACCOUNT_FIND_BY_NAME,
    						new Object[] { username });
     
     
    		bookStock.setStock(bookStock.getStock() - 1);
     
    		if ((account.getBalance() - book.getPrix()) < 0) {
    			throw new Exception(
    					"tu ne peux pas acheter ce livre");
    		}
     
    		account.setBalance(account.getBalance() - book.getPrix());
    	}
     
    	@Transactional
    	public void checkout(List<String> isbns, String username) throws Exception{
    		for (String isbn : isbns) {
    			purchase(isbn, username);
    		}
    	}
    et le test
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    shop.checkout(Arrays.asList("123456","123457"), "james");
    je fais en sorte dans la base de données d'avoir l'exception au deuxieme tour de boucle pour voir si la premiere va etre 'rollbacké'. Pour moi vu que par defaut dans spring la propagation est de type Required il doit y avoir un rollback chose qui n'est pas faite ie le premier tour de boucle est commité

    est ce j'ai louppé un truc dans mon raisonnement?

    merci par avance de vos reponse

  2. #2
    Expert éminent
    Avatar de djo.mos
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    4 666
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2004
    Messages : 4 666
    Points : 7 679
    Points
    7 679
    Par défaut
    Salut,
    Peut être que la gestion des transactions par Spring n'est tout simplement pas (correctement) configurée ? Tu peux nous montrer la définition de ton application context ?

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    185
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 185
    Points : 109
    Points
    109
    Par défaut
    merci pour ta réponce

    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
     
    <?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:context="http://www.springframework.org/schema/context"
    	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:util="http://www.springframework.org/schema/util" xmlns:p="http://www.springframework.org/schema/p"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
           http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
     
     
    	<bean id="entityManagerFactory"
    		class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    		<property name="persistenceUnitName" value="springSupport" />
    	</bean>
     
    	<bean
    		class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
     
    	<context:annotation-config />
     
    	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
    		p:entityManagerFactory-ref="entityManagerFactory" />
     
     
    	<context:component-scan base-package="com" />
    	<tx:annotation-driven transaction-manager="transactionManager" />
     
    	<aop:aspectj-autoproxy />
    	<bean id="exceptionHandler" class="ExceptionHandler" />
     
    </beans>

Discussions similaires

  1. Problème de rollback
    Par jakcam dans le forum JDBC
    Réponses: 1
    Dernier message: 12/12/2008, 11h45
  2. Require problème d'affichage
    Par Cedrun dans le forum Langage
    Réponses: 2
    Dernier message: 04/06/2008, 09h17
  3. problème de rollback segment
    Par valauga dans le forum Administration
    Réponses: 5
    Dernier message: 29/11/2007, 18h21
  4. [TSQL]problème de Rollback sybase
    Par rasybase dans le forum Adaptive Server Enterprise
    Réponses: 4
    Dernier message: 23/11/2007, 12h13
  5. Problème de Rollback 2
    Par Monstros Velu dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 26/04/2006, 17h54

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