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 :

[Transaction] Probleme de profondeur [Data]


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 36
    Par défaut [Transaction] Probleme de profondeur
    Bonjour,
    J'ai un gros souci avec hibernate. Je m'explique.

    J'ai des dao, qui sont transactionnels. Et j'ai un "service" qui appel plusieurs DAO a la suite.

    En gros ma classe Service ressemble a ca:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    class Service {
    DAO1 dao1;
    DAO2 dao2
     
    DAO1 getDAO1() {return dao1;}
    DAO2 getDAO2() {return dao2;}
     
    void createObject() {
    dao1.insert(...);
    dao2.insert(...);
    }
     
    }
    La declaration des 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
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
     
        <!-- The transaction manager -->
        <bean id="nmciTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory">
                <ref bean="sessionFactory"/>
            </property>
            <property name="nestedTransactionAllowed">
                <value>true</value>
            </property>
        </bean>
     
        <!-- The DAO transaction advice -->
        <!-- All methods are transactionnal, methods that start with "find" are readOnly, all other methods are rollback-able -->
        <tx:advice id="nmciDAOTransactionAdvice" transaction-manager="nmciTransactionManager">
        <tx:attributes>
          <tx:method name="find*" read-only="true" propagation="NEVER"/>
          <tx:method name="get*" read-only="true" propagation="NEVER"/>
          <tx:method name="save*" read-only="false" propagation="NESTED" rollback-for="DAOException,DAOLockException,org.springframework.dao.DataAccessException"/>
          <tx:method name="create*" read-only="false" propagation="NESTED" rollback-for="DAOException,DAOLockException,org.springframework.dao.DataAccessException"/>
          <tx:method name="insert*" read-only="false" propagation="NESTED" rollback-for="DAOException,DAOLockException,org.springframework.dao.DataAccessException"/>
          <tx:method name="update*" read-only="false" propagation="NESTED" rollback-for="DAOException,DAOLockException,org.springframework.dao.DataAccessException"/>
          <tx:method name="delete*" read-only="false" propagation="NESTED" rollback-for="DAOException,DAOLockException,org.springframework.dao.DataAccessException"/>
        </tx:attributes>
      </tx:advice>    
     
        <!-- Defines the DAO aop pointcuts -->
      <aop:config>
        <aop:pointcut id="daoOperation" expression="execution(* com.miat.nmci.dao..*DAO.*(..))"/>
        <aop:advisor pointcut-ref="daoOperation" advice-ref="nmciDAOTransactionAdvice" />
      </aop:config> 
     
         <!-- The DAO transaction advice -->
        <!-- All methods are transactionnal, methods that start with "find" are readOnly, all other methods are rollback-able, except method that start with "get" or "set" that are not transactionnal at all -->
        <tx:advice id="nmciServiceTransactionAdvice" transaction-manager="nmciTransactionManager">
        <tx:attributes>
          <tx:method name="get*" propagation="NEVER"/>
          <tx:method name="set*" propagation="NEVER"/>
          <tx:method name="find*" read-only="true" propagation="NEVER"/>
          <tx:method name="create*" read-only="false" propagation="NESTED" rollback-for="DAOException,DAOLockException,org.springframework.dao.DataAccessException"/>
          <tx:method name="insert*" read-only="false" propagation="NESTED" rollback-for="DAOException,DAOLockException,org.springframework.dao.DataAccessException"/>
          <tx:method name="update*" read-only="false" propagation="NESTED" rollback-for="DAOException,DAOLockException,org.springframework.dao.DataAccessException"/>
          <tx:method name="delete*" read-only="false" propagation="NESTED" rollback-for="DAOException,DAOLockException,org.springframework.dao.DataAccessException"/>
        </tx:attributes>
      </tx:advice>    
     
        <!-- Defines the service aop pointcuts -->
      <aop:config>
        <aop:pointcut id="serviceOperation" expression="execution(* com.miat.nmci.services..*Service.*(..))"/>
        <aop:advisor pointcut-ref="daoOperation" advice-ref="nmciDAOTransactionAdvice" />
      </aop:config>
    Mon probleme est que dans le service, j'ai une methode qui fais appel a plusieurs dao:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    void createObject() {
    dao1.insert(...);
    dao2.insert(...);
    }
    Mais ca ne marche pas!! En fait, si j'ai une exception durant dao2.insert, ce que j'ai inseré dans dao1.insert est en base, alors que ca ne devrai pas logiquement. Apparamment le rollback se fais sur les DAO et pas sur le service. Comment faire pour que dans ce cas precis la transaction se fasse au niveau du service et pas du dao(sachant que je fais parfois appel a dao.insert() hors du service, et que donc je dois tout de meme conserver les dao transactionnels)?

    Quelqu'un a t'il une idée du pourquoi et du comment?

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 36
    Par défaut
    J'ai rassemblé deux elements <aop:config> et ca amrche...

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

Discussions similaires

  1. Probleme de profondeur
    Par GTJuanpablo dans le forum Mise en page CSS
    Réponses: 3
    Dernier message: 27/09/2007, 11h19
  2. Réponses: 1
    Dernier message: 25/05/2007, 17h53
  3. probleme de profondeur et loadVar
    Par shloka dans le forum Flash
    Réponses: 1
    Dernier message: 10/04/2007, 08h57
  4. Probleme de profondeur setDepth
    Par Manwel dans le forum Flash
    Réponses: 3
    Dernier message: 07/08/2006, 21h21
  5. [JDBC] probleme avec les transactions
    Par lthomas dans le forum JDBC
    Réponses: 2
    Dernier message: 17/06/2005, 17h10

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