Bonjour,

J'ai un soucis de compréhension de l'utilisation de la Transaction Hibernate injecté par Spring sur une méthode de mon service

Voilà la configuration de Spring

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
<?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:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
	                    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
 
   <context:component-scan base-package="com.leaderinfo.novanet" />
 
	<bean id="propertyConfigurer"
		class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
		<property name="location" value="classpath:julien.properties" />
	</bean>
 
   <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
      	<property name="driverClass"><value>${jdbc.driverClass}</value></property>
      	<property name="jdbcUrl"><value>${jdbc.url}</value></property>
      	<property name="user"><value>${jdbc.username}</value></property>
      	<property name="password"><value>${jdbc.password}</value></property>
      	<property name="checkoutTimeout"><value>${c3p0.checkoutTimeout}</value></property>
        <property name="minPoolSize"><value>${c3p0.minPoolSize}</value></property>
        <property name="maxPoolSize"><value>${c3p0.maxPoolSize}</value></property>
        <property name="maxIdleTime"><value>${c3p0.maxIdleTime}</value></property>
        <property name="maxConnectionAge"><value>${c3p0.maxConnectionAge}</value></property>
        <property name="acquireIncrement"><value>${c3p0.acquireIncrement}</value></property>
        <property name="maxStatements"><value>180</value></property>
        <property name="propertyCycle"><value>${c3p0.propertyCycle}</value></property>
        <property name="unreturnedConnectionTimeout"><value>${c3p0.unreturnedConnectionTimeout}</value></property>
        <property name="autoCommitOnClose"><value>${c3p0.autoCommitOnClose}</value></property>
        <property name="preferredTestQuery"><value>${c3p0.preferredTestQuery}</value></property>
   </bean>
 
   <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
      	<property name="dataSource"><ref local="dataSource"/></property>
      	<property name="hibernateProperties">
	     	<props>
	       		<prop key="hibernate.dialect">
	         		org.hibernate.dialect.MySQLDialect
	       		</prop>
	       		<prop key="hibernate.show_sql">
	         		true
	       		</prop>
	     	</props>
 
      	<property name="annotatedClasses">
			<list>
				<value>com.leaderinfo.novanet.entity.commons.CurrentSelection</value>
				<value>com.leaderinfo.novanet.entity.commons.JoueursFoot</value>
			</list>
	  	</property>
   </bean>
 
   <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
     	<property name="sessionFactory" ref="sessionFactory" />
   </bean>
 
    <tx:advice id="serviceTxAdvice" transaction-manager="txManager">
     <tx:attributes>
       <tx:method name="find*" propagation="REQUIRED" read-only="true" />
       <tx:method name="get*" propagation="REQUIRED" read-only="true" />
       <tx:method name="*" propagation="REQUIRED" />
     </tx:attributes>
   </tx:advice>
 
   <aop:config>
     <aop:pointcut id="abstractServiceMethods"
         expression="execution(* com.leaderinfo.novanet.services.AbstractService.*(..))" />
     <aop:advisor advice-ref="serviceTxAdvice" pointcut-ref="abstractServiceMethods" />
   </aop:config>
 
   <aop:config>
     <aop:pointcut id="servicesMethods"
         expression="execution(* com.leaderinfo.novanet.services.*.*Service.*(..))" />
     <aop:advisor advice-ref="serviceTxAdvice" pointcut-ref="servicesMethods" />
   </aop:config>
 
   </aop:config>
 
</beans>
Ci dessous, le contenu de ma méthode du service que je teste

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
public void doMyTest() {
		CurrentSelection currentSelection = new CurrentSelection();
		currentSelection.setLogin("julien");
		currentSelection.setSocieteuser("toto");
 
		CurrentSelection currentSelection2 = new CurrentSelection();
		currentSelection2.setSocieteuser("toto2");
 
		this.insert(currentSelection);
		this.insert(currentSelection2);
	}
Le premier insert s'effectue correctement et c'est normal. Le deuxième insert ne doit pas passer à cause de la non initialisation de la clé primaire (login)

Problème, selon la définition des mes AOP pour les transactions, ca devrait rollback toute la méthode, or ca ne rollback pas le premier insert. Pourquoi ?

Comment palier à cela ?

Merci