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 :

Comment controler le bon fonctionnement des transactions?


Sujet :

Spring Java

  1. #1
    Membre confirmé
    Avatar de irnbru
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2004
    Messages
    316
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Juin 2004
    Messages : 316
    Points : 500
    Points
    500
    Billets dans le blog
    1
    Par défaut Comment controler le bon fonctionnement des transactions?
    Hello à tous Je m'excuse de poser une question certainement stupide, mais je suis débutant. Je souhaitais savoir s'il existe un moyen de vérifier le bon fonctionnement des transactions de mes opérations avec hibernate de mon application web.

    Pour info voici le service avec les opérations devant utiliser les transactions:

    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
     
    package net.developpez.irnbru.tutorial.service;
     
    import java.util.List;
     
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Propagation;
    import org.springframework.transaction.annotation.Transactional;
     
    import net.developpez.irnbru.tutorial.dao.SourceDao;
    import net.developpez.irnbru.tutorial.domain.Hello;
    import net.developpez.irnbru.tutorial.exception.MaException;
     
    @Service("MonService")
    public class SourceServiceImpl implements SourceService {
     
    	@Autowired
    	private SourceDao dao;
     
    	@Override
    	@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW)
    	public List<xxx> findall() {		
    		return dao.findall();
    	}
     
    	@Override
    	@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
    	public void add(xxx yyy) {
    		dao.add(xxx);		
    	}
     
    }
    et la config

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
     
    <bean name="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    		<property name="sessionFactory" ref="sessionfactory"></property>
    	</bean>
     
    	<tx:annotation-driven transaction-manager="transactionManager"/>
    Cela a l'air de marcher, car je vois dans les logs:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    2010-04-28 15:08:52,604 [http-8080-1] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Creating new transaction with name [net.developpez.irnbru.tutorial.service.SourceService.add]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT
    ......
    2010-04-28 15:08:53,135 [http-8080-1] DEBUG org.hibernate.transaction.JDBCTransaction - begin
     
    2010-04-28 15:08:53,135 [http-8080-1] DEBUG org.hibernate.jdbc.ConnectionManager - opening JDBC connection
    2010-04-28 15:08:53,135 [http-8080-1] DEBUG org.hibernate.transaction.JDBCTransaction - current autocommit status: true
    2010-04-28 15:08:53,135 [http-8080-1] DEBUG org.hibernate.transaction.JDBCTransaction - disabling autocommit
    2010-04-28 15:08:53,229 [http-8080-1] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Exposing Hibernate transaction as JDBC transaction [jdbc:mysql://localhost/test, UserName=irnbru@localhost, MySQL-AB JDBC Driver]
    2010-04-28 15:08:53,229 [http-8080-1] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager - Bound value [org.springframework.jdbc.datasource.ConnectionHolder@a193fe] for key [org.apache.commons.dbcp.BasicDataSource@149f041] to thread [http-8080-1]
    2010-04-28 15:08:53,229 [http-8080-1] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager - Bound value [org.springframework.orm.hibernate3.SessionHolder@1c8f91e] for key [org.hibernate.impl.SessionFactoryImpl@1fb2ef9] to thread [http-8080-1]
    2010-04-28 15:08:53,229 [http-8080-1] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager - Initializing transaction synchronization
    2010-04-28 15:08:53,229 [http-8080-1] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager - Retrieved value [org.springframework.orm.hibernate3.SessionHolder@1c8f91e] for key [org.hibernate.impl.SessionFactoryImpl@1fb2ef9] bound to thread [http-8080-1]
    2010-04-28 15:08:53,229 [http-8080-1] DEBUG org.springframework.transaction.support.TransactionSynchronizationManager - Retrieved value [org.springframework.orm.hibernate3.SessionHolder@1c8f91e] for key [org.hibernate.impl.SessionFactoryImpl@1fb2ef9] bound to thread [http-8080-1]
    Y a t il un moyen de vérifier le bon fonctionnement des transactions sans passer par les logs en mode DEBUG, horrible surtout en production! Les admins diront non !

    J'ai inclus les logs au cas où vous les demanderiez.

    Merci de votre aide
    IRNBRU
    Fichiers attachés Fichiers attachés
    • Type de fichier : txt log.txt (56,7 Ko, 120 affichages)

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 79
    Points : 73
    Points
    73
    Par défaut
    Bonjour,

    Avec log4j il y'a moyen d'orienter tes logs vers page web, voir même vers la base de données. Peut être que ça peut t'aider ....

  3. #3
    Membre confirmé
    Avatar de irnbru
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2004
    Messages
    316
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Juin 2004
    Messages : 316
    Points : 500
    Points
    500
    Billets dans le blog
    1
    Par défaut
    fadjerx Merci pour ton aide, mais ma question est plutot de savoir comment identifier dans les logs le fonctionnement des transactions? Afin de pouvoir justement les indentifier. Car tu me suggeres là d'envoyer les logs vers une page web, ok. Mais je souhaite récupérer tous les logs significatifs vis à vis des transactions... Et c'est assez lourd et complexe

    IRNBRU

  4. #4
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 79
    Points : 73
    Points
    73
    Par défaut
    oui ce que tu peux faire c'est d'identifier tous les packages java Spring qui interviennent dans les transactions, et leur associer un appender log4j spécial, qui va par exemple écrire une page web toutes les nuits ....

    Une chose importante, dans cette config du log4j il faut que tu mettes le niveau de log à debug pour voir justement que les transactions sont bien lancées, et sur les bonnes méthodes.

  5. #5
    Membre actif Avatar de aymen83
    Inscrit en
    Décembre 2007
    Messages
    271
    Détails du profil
    Informations forums :
    Inscription : Décembre 2007
    Messages : 271
    Points : 268
    Points
    268
    Par défaut
    tu peux utiliser spring AOP. Tu peux utiliser les aspects pour logger tes méthodes annotées avec @Transactionel

  6. #6
    Membre confirmé
    Avatar de irnbru
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2004
    Messages
    316
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Juin 2004
    Messages : 316
    Points : 500
    Points
    500
    Billets dans le blog
    1
    Par défaut
    Merci à vous deux pour vos suggestions.

    J'ai demandé à un appender de log4j de logger dans un fichier à part les opérations effectuées par HibernateTransactionManager. J'ai mis en mode DEBUG. J'ai mis un roll back barbare dans mon code. Cela a donné les logs suivants. Cela parait bien fonctionner car l'ajout n'a plus lieu.

    J'ai mis en rouge les logs avec roll back (scroller les logs vers le bas un peu longs )

    fadjerx comment procèdes tu pour mettre ces logs dans une page web?

    aymen83 peux-tu m'expliquer comment un aspect visant les méthodes annotées @Transactional pourraient m'aider à vérifer que les transactions soient bien effectives en internes?

    Une dernière question que je me pose est lorsque ma classe a des méthodes @Transactional

    - ma classe serait décorée par proxy une seule fois?
    - Ou alors elle serait seulement décorée lors de l'exécution d'une méthode @Transactional, et ceci à chaque fois?

    Merci
    IRNBRU


    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
    2010-04-29 15:34:22,218 [main] INFO  org.springframework.orm.hibernate3.HibernateTransactionManager - Using DataSource [org.apache.commons.dbcp.BasicDataSource@3727c5] of Hibernate SessionFactory for HibernateTransactionManager
    2010-04-29 15:34:28,796 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Using transaction object [org.springframework.orm.hibernate3.HibernateTransactionManager$HibernateTransactionObject@114d18f]
    2010-04-29 15:34:28,796 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Creating new transaction with name [net.developpez.irnbru.tutorial.service.SourceService.findall]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT,readOnly
    2010-04-29 15:34:28,890 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Opened new Session [org.hibernate.impl.SessionImpl@1a1f370] for Hibernate transaction
    2010-04-29 15:34:28,906 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Preparing JDBC Connection of Hibernate Session [org.hibernate.impl.SessionImpl@1a1f370]
    2010-04-29 15:34:28,937 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Exposing Hibernate transaction as JDBC transaction [jdbc:mysql://localhost/test, UserName=irnbru@localhost, MySQL-AB JDBC Driver]
    2010-04-29 15:34:29,390 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering beforeCommit synchronization
    2010-04-29 15:34:29,390 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering beforeCompletion synchronization
    2010-04-29 15:34:29,390 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Initiating transaction commit
    2010-04-29 15:34:29,390 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Committing Hibernate transaction on Session [org.hibernate.impl.SessionImpl@1a1f370]
    2010-04-29 15:34:29,390 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering afterCommit synchronization
    2010-04-29 15:34:29,390 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering afterCompletion synchronization
    2010-04-29 15:34:29,390 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Closing Hibernate Session [org.hibernate.impl.SessionImpl@1a1f370] after transaction
    2010-04-29 15:34:52,359 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Using transaction object [org.springframework.orm.hibernate3.HibernateTransactionManager$HibernateTransactionObject@4d28c7]
    2010-04-29 15:34:52,359 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Creating new transaction with name [net.developpez.irnbru.tutorial.service.SourceService.add]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT
    2010-04-29 15:34:52,359 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Opened new Session [org.hibernate.impl.SessionImpl@1b044df] for Hibernate transaction
    2010-04-29 15:34:52,359 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Preparing JDBC Connection of Hibernate Session [org.hibernate.impl.SessionImpl@1b044df]
    2010-04-29 15:34:52,359 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Exposing Hibernate transaction as JDBC transaction [jdbc:mysql://localhost/test, UserName=irnbru@localhost, MySQL-AB JDBC Driver]
    2010-04-29 15:34:52,390 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Transactional code has requested rollback
    2010-04-29 15:34:52,390 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering beforeCompletion synchronization
    2010-04-29 15:34:52,390 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Initiating transaction rollback
    2010-04-29 15:34:52,390 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Rolling back Hibernate transaction on Session [org.hibernate.impl.SessionImpl@1b044df]
    2010-04-29 15:34:52,468 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering afterCompletion synchronization
    2010-04-29 15:34:52,468 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Closing Hibernate Session [org.hibernate.impl.SessionImpl@1b044df] after transaction
    2010-04-29 15:34:52,484 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Using transaction object [org.springframework.orm.hibernate3.HibernateTransactionManager$HibernateTransactionObject@1627c16]
    2010-04-29 15:34:52,484 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Creating new transaction with name [net.developpez.irnbru.tutorial.service.SourceService.findall]: PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT,readOnly
    2010-04-29 15:34:52,484 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Opened new Session [org.hibernate.impl.SessionImpl@c0890f] for Hibernate transaction
    2010-04-29 15:34:52,484 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Preparing JDBC Connection of Hibernate Session [org.hibernate.impl.SessionImpl@c0890f]
    2010-04-29 15:34:52,484 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Exposing Hibernate transaction as JDBC transaction [jdbc:mysql://localhost/test, UserName=irnbru@localhost, MySQL-AB JDBC Driver]
    2010-04-29 15:34:52,484 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering beforeCommit synchronization
    2010-04-29 15:34:52,484 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering beforeCompletion synchronization
    2010-04-29 15:34:52,484 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Initiating transaction commit
    2010-04-29 15:34:52,484 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Committing Hibernate transaction on Session [org.hibernate.impl.SessionImpl@c0890f]
    2010-04-29 15:34:52,484 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering afterCommit synchronization
    2010-04-29 15:34:52,500 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Triggering afterCompletion synchronization
    2010-04-29 15:34:52,500 [http-8080-2] DEBUG org.springframework.orm.hibernate3.HibernateTransactionManager - Closing Hibernate Session [org.hibernate.impl.SessionImpl@c0890f] after transaction

  7. #7
    Membre régulier
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 79
    Points : 73
    Points
    73
    Par défaut
    Bonjour,

    C'est bien tu as bien avancé !

    Pour ce qui est de la décoration de ta classe pour les transactions elle est faite au démarrage de Spring, met toutes les classe Spring en Debug et tu verras ce comportement ....

    Pour sortir ton fichier de log en page HTML tu as deux méthodes :
    + Simple et basic : utilises le HTMLLayout, un petit googlage et tu trouveras des exemples
    + Méthode sophistiquée et laborieuse ;-) : oriente tes logs vers une base de données, et fait un peu de code pour construire ta page dynamiquement.

    Bonne chance.

  8. #8
    Membre confirmé
    Avatar de irnbru
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2004
    Messages
    316
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Juin 2004
    Messages : 316
    Points : 500
    Points
    500
    Billets dans le blog
    1
    Par défaut
    Merci fadjerx Je ferai ca mettre le package de base de spring en debug puis mettre les logs encore à part pour voir le comportement de Spring en général. Toutes les classes des autres sous packages heriteront le mode DEBUG.

    Spring est bien mais comme tout tool il faut quand meme explorer le code afin de mieux maitriser.

    J'explore le code spring en ce moment. Immense tache, mais c un plaisirs de voir à tel point leur code est bien écrit. On apprends bcp! Le codeur Juergen Hoeller est vraiment fort.

    IRNBRU

Discussions similaires

  1. Fonctionnement des transactions
    Par clouddd dans le forum Développement
    Réponses: 4
    Dernier message: 05/07/2012, 17h22
  2. Comment vérifier le bon fonctionnement d'un cron
    Par homers dans le forum Administration système
    Réponses: 1
    Dernier message: 07/01/2010, 08h20
  3. Vérifier le bon fonctionnement des tâches planifiées
    Par _FaFa_ dans le forum Programmation et administration système
    Réponses: 4
    Dernier message: 18/12/2008, 10h35
  4. [Delphi - Firebird] Comment faire bon usage des transactions?
    Par Lili21 dans le forum Connexion aux bases de données
    Réponses: 2
    Dernier message: 07/05/2007, 20h59
  5. Réponses: 2
    Dernier message: 03/09/2006, 10h03

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