Bonjour,

J'ai une application Spring MVC version 4.2.4.
J'ai des annotations @Transactionnal sur ma couche service.
Le problème est que j'avais autocommit à true sur ma BDD PostgrESQL et mes transactions ne se faisait pas.
Du coup j'ai surchargé getConnection afin de mettre autocommit à false :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
public class TransactionalDataSource extends DriverManagerDataSource {
 
	@Override
	public Connection getConnection() throws SQLException {
		Connection c = super.getConnection();
		c.setAutoCommit(false);
		return c;
	}
 
}
Maintenant le problème c'est qu'aucune donnée ne persiste maintenant. Les transactions ne fonctionnent donc pas.

Voici un exemple d'une classe de ma couche 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
	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
	public int louerPaiementDirect(int idAdherent, int idJeu, String dateSortie, String dateRetourPrevue, String commentaireSortie) throws ExceptionMetier, ExceptionTechnique {
		Adherent adherent = null;
		try {
			adherent = adherentDao.getAdherent(idAdherent);
		} catch (ExceptionTechnique e) {
			// TODO: handle exception
		}
		Jeu jeu = jeuDao.getJeu(idJeu);
		Pret pret = new Pret();
		pret.setAdherent(adherent);
		pret.setJeu(jeu);
		pret.setDateSortie(DateUtils.getDateFromDatePicker(dateSortie));
		pret.setDateRetourPrevue(DateUtils.getDateFromDatePicker(dateRetourPrevue));
 
		pret.setCommentaireSortie(commentaireSortie);
		int idPret = pretDao.creerPret(pret);
 
		//throw new RuntimeException();
 
		//TODO créer une opération
		Operation operation = new Operation();
		operation.setAdherent(adherent);
		operation.setDateOperation(DateUtils.getDateFromDatePicker(dateSortie));
		operation.setDateReglement(DateUtils.getDateFromDatePicker(dateSortie));
		operation.setModeReglement(paramLudoDao.getParamLudo(ModeReglement.class, "mode_reglement", ModeReglement.TIRELIRE));
		operation.setPrestation(jeu.getCategorie().getPrestation());
		operation.setMontant(operation.getPrestation().getCout());
		operation.setCredit(false);
		operationDao.creerOperation(operation);
 
		adherent.setTirelire(adherent.getTirelire() - jeu.getCategorie().getPrestation().getCout());
		return idPret;
	}
Dans mes DAO je ne fais donc aucun commit manuel. Ceci étant censé être géré par Spring.

Auriez-vous une piste ?