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 3 Mutliple Transaction Manager


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Développeur Java
    Inscrit en
    Octobre 2009
    Messages
    169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Octobre 2009
    Messages : 169
    Par défaut Spring 3 Mutliple Transaction Manager
    Bonjour,

    J'ai deux entityManager de déclaré dans mon fichier de configuration.
    Un pour ma partie business et un pour ma partie batch notamment.

    fichier de configuration 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
    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
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
     
    <bean id="dataSource1" class="org.apache.commons.dbcp.BasicDataSource"
    	destroy-method="close">
    	<property name="driverClassName" value="${1.driver}" />
    	<property name="url" value="${1.url}" />
    	<property name="username" value="${1.username}" />
    	<property name="password" value="${1.password}" />
    	<property name="timeBetweenEvictionRunsMillis" value="300000" />
    	<property name="numTestsPerEvictionRun" value="6" />
    	<property name="minEvictableIdleTimeMillis" value="1800000" />
    	<property name="initialSize" value="3" />
    	<property name="maxActive" value="10" />
    	<property name="maxIdle" value="10" />
    	<property name="maxWait" value="5000" />
    	<property name="poolPreparedStatements" value="true" />
    	<property name="maxOpenPreparedStatements" value="100" />
    </bean>
     
    <bean id="dataSource2" class="org.apache.commons.dbcp.BasicDataSource"
    	destroy-method="close">
    	<property name="driverClassName" value="${2.driver}" />
    	<property name="url" value="${2.url}" />
    	<property name="username" value="${2.username}" />
    	<property name="password" value="${2.password}" />
    	<property name="timeBetweenEvictionRunsMillis" value="300000" />
    	<property name="numTestsPerEvictionRun" value="6" />
    	<property name="minEvictableIdleTimeMillis" value="1800000" />
    	<property name="initialSize" value="3" />
    	<property name="maxActive" value="10" />
    	<property name="maxIdle" value="10" />
    	<property name="maxWait" value="5000" />
    	<property name="poolPreparedStatements" value="true" />
    	<property name="maxOpenPreparedStatements" value="100" />
    </bean>
     
    <bean id="EntityManagerFactory1"
    	class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    	depends-on="transactionManager1">
    	<property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence" />
    	<property name="persistenceXmlLocation" value="classpath:META-INF/1.xml" />
    	<property name="persistenceUnitName" value="1" />
    	<property name="dataSource" ref="dataSource1" />
    	<property name="jpaVendorAdapter">
    		<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    			<property name="showSql" value="true" />
    			<property name="generateDdl" value="true" />
    			<property name="databasePlatform" value="${1.dialect}" />
    			</bean>
    	</property>
    </bean>
     
    <bean id="transactionManager1" class="org.springframework.orm.jpa.JpaTransactionManager">
    	<property name="entityManagerFactory" ref="EntityManagerFactory1" />
    	<property name="dataSource" ref="dataSource1" />
    </bean>
     
    <bean id="EntityManagerFactory2"
    	class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    	depends-on="transactionManager2">
    	<property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence" />
    	<property name="persistenceXmlLocation" value="classpath:META-INF/2.xml" />
    	<property name="persistenceUnitName" value="2" />
    	<property name="dataSource" ref="dataSource2" />
    	<property name="jpaVendorAdapter">
    		<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    			<property name="showSql" value="true" />
    			<property name="generateDdl" value="true" />
    			<property name="databasePlatform" value="${2.dialect}" />
    			</bean>
    	</property>
    </bean>
     
    <bean id="transactionManager2" class="org.springframework.orm.jpa.JpaTransactionManager">
    	<property name="entityManagerFactory" ref="EntityManagerFactory2" />
    	<property name="dataSource" ref="dataSource2" />
    </bean>
     
    <tx:advice id="daoTxAdvice1" transaction-manager="transactionManager1">
    	<tx:attributes>
    		<tx:method name="get*" propagation="REQUIRED" read-only="true" />
    		<tx:method name="*" propagation="REQUIRED" />
    	</tx:attributes>
    </tx:advice>
     
    <tx:advice id="daoTxAdvice2" transaction-manager="transactionManager2">
    	<tx:attributes>
    		<tx:method name="get*" propagation="REQUIRED" read-only="true" />
    		<tx:method name="*" propagation="REQUIRED" />
    	</tx:attributes>
    </tx:advice>
    Avec une configuration en Aspect pour activer le mode transactionnelle sur certain package :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    <aop:config proxy-target-class="true">
    	<aop:advisor advice-ref="daoTxAdvice1"
    		pointcut="execution(* fr.organisation.appli.*.* (..))" />
    </aop:config>
    <aop:config proxy-target-class="true">
    	<aop:advisor advice-ref="daoTxAdvice2"
    		pointcut="execution(* fr.organisation.appli.*.* (..))" />
    </aop:config>
    Tout fonctionnait bien jusqu'au moment ou une des class à eu besoin d'accéder aux deux instances dans la même méthode.
    Ma méthode accède au données de la première datasource et doit à la fin écrire un enregistrement dans la seconde dataSource.
    Je vois bien les traces d'Hibernate avec les requêtes. Mon numéro de séquence de pojo est bien incrémenté. la requête sql d'hibernate est correct.
    mais au final l'insert ne se fait pas.

    Question comment traiter ce cas ?

    D'avance merci de vos lumières,

    HadanMarv

  2. #2
    Membre confirmé
    Homme Profil pro
    Développeur Java
    Inscrit en
    Octobre 2009
    Messages
    169
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Octobre 2009
    Messages : 169
    Par défaut
    est-ce que mon problème est incompréhensible ?

Discussions similaires

  1. [Data] JPA managé par Spring 2.5 - transaction
    Par nean_j dans le forum Spring
    Réponses: 9
    Dernier message: 25/02/2011, 13h58
  2. [Framework] Challenge ! Spring + Hibernate = double transaction ?
    Par Invité dans le forum Spring
    Réponses: 2
    Dernier message: 22/10/2009, 10h19
  3. [Data] Spring: gestion des transactions
    Par dkwasiborski dans le forum Spring
    Réponses: 8
    Dernier message: 19/05/2009, 13h14
  4. [Data] [Transaction] @transactional et multiple transaction manager
    Par trungsi dans le forum Spring
    Réponses: 1
    Dernier message: 08/02/2009, 20h51
  5. [Data] [Spring DAO][JPA] JPA managé par Spring 2.5
    Par Ylias dans le forum Spring
    Réponses: 2
    Dernier message: 09/06/2008, 19h48

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