J'ai le problèmes suivant. Je n'arrive pas a rendre l'exécution des méthodes de mes services atomique
j'ai configurer les transactions comme cela avec SPRING + HIBERNATE + GenericDao (du site d'IBM)
NB: si je met tout en read only j'ai bien une erreur et pas d'enregistrement en base donc je pense que l'aop fonctionne.
Avec le service
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 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/myDB" /> <property name="username" value="root" /> <property name="password" value="toto" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="mappingResources"> <list> <value>com/nicollet/generics/server/object/Hibernate.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <!-- Generic Dao --> <bean id="finderIntroductionAdvisor" class="com.nicollet.generics.server.dao.genericdao.finder.impl.FinderIntroductionAdvisor"/> <bean id="extendedFinderNamingStrategy" class="com.nicollet.generics.server.dao.genericdao.finder.impl.ExtendedFinderNamingStrategy" /> <bean id="abstractDaoTarget" class="com.nicollet.generics.server.dao.genericdao.impl.GenericDaoHibernateImpl" abstract="true"> <property name="sessionFactory" ref="sessionFactory"/> <property name="namingStrategy" ref="extendedFinderNamingStrategy" /> </bean> <bean id="abstractDao" class="org.springframework.aop.framework.ProxyFactoryBean" abstract="true"> <property name="interceptorNames"> <list> <value>finderIntroductionAdvisor</value> </list> </property> </bean> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="*" propagation="REQUIRED" read-only="true"/> <tx:method name="save*" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <aop:config> <aop:advisor pointcut="execution(* com.nicollet.generics.server.service.rpc.*ServiceImpl.*(..))" advice-ref="txAdvice" /> </aop:config> <bean id="personDao" parent="abstractDao"> <property name="proxyInterfaces" value="com.nicollet.generics.server.dao.PersonDao" /> <property name="target"> <bean parent="abstractDaoTarget"> <constructor-arg value="com.nicollet.generics.server.object.Person" /> </bean> </property> </bean> <bean name="rpcSecurityService" class="com.nicollet.generics.server.service.rpc.SecurityServiceImpl"> <property name="personDao" ref="personDao"/> </bean>
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 public class SecurityServiceImpl implements SecurityService { private PersonDao personDao; public User saveNewPerson(Person person) { personDao.create(person); //DEBUG pour provoquer une exception personDao.create(null); return user; } public void setPersonDao(PersonDao personDao) { this.personDao = personDao; } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 public interface PersonDao extends GenericDao<Person, Integer> { }Je voudrais un rollback sur le premier create mais en fait il n'y en a pas.
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 public class GenericDaoHibernateImpl<T, ID extends Serializable> extends HibernateDaoSupport implements GenericDao<T, ID>, FinderExecutor<T> { private FinderNamingStrategy<T> namingStrategy = new SimpleFinderNamingStrategy<T>(); private FinderArgumentTypeFactory argumentTypeFactory = new SimpleFinderArgumentTypeFactory(); private Class<T> type; public GenericDaoHibernateImpl(Class<T> type) { this.type = type; } @SuppressWarnings("unchecked") public ID create(T object) { return (ID) getHibernateTemplate().save(object); } ...
Je ne sais pas comment faire.
Partager