Bonjour,

Je suis en train de développer un batch avec Spring Batch.

Je suis en phase de tests et j'ai remarqué qu'en cas d'exception, aucun rollback ne s'effectue.

J'explique la situation.

Dans mon reader, je récupère les données nécessaires.
Dans mon writer, je les parcours pour créer un XML et un fichier texte et à la fin je les flague et je crée un historique.

Or après la création de l'historique, je fais exprès de lever une exception pour qu'il rentre dans le catch. Et dans le catch, je flague à Error et je crée un historique à Error.

Et en base, j'ai deux historiques, celui qui correspond au cas où tout s'est bien passé, et un historique dans l'exception

Voici le code de mon writer
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
    @Override
    protected void doWrite(List<? extends XXPP> arg0) throws Exception {
 
        XXPP xxItem = (XXPP) arg0.get(0);
        List<File> files = new ArrayList<File>();
 
        if (xxItem != null && xxItem.getXX() != null && !xxItem.getXX().isEmpty()) {
 
            try {
                /*---------------------------------------------*/
                /*-------CREATE AND COPY A XML FILE -----------*/
                /*---------------------------------------------*/
                //Create the xml content
                String xmlFile = fileServiceXML.create(xxItem);
 
                //copy the content in xml file
                FilesUtility.copyXMLFileWithTimestampName(xmlFile, Utility.getSubFolderAccounting());
 
                log.info(xmlFile);
 
                /*--------------------------------------------------------------------*/
                /*-------CREATE AND COPY A RECONCILIATION FILE (FLAT FILE) -----------*/
                /*--------------------------------------------------------------------*/
                //create a bean from the database object
                FitAccountingReconciliationBean reconcilationBean = Utility.createReconciliationBean(xxItem);
 
                //create the text content
                String reconciliatonFile = fileServicesReconFile.create(reconcilationBean);
 
                //copy the content in text file
                files.add(FilesUtility.copyTextFileWithTimestampName(reconciliatonFile, Utility.getSubFolderAccounting()));
 
                log.info(reconciliatonFile);
 
                /*------------------------------------------------------------------------------*/
                /*-------------UPDATE STATUS AND TRANSACTION_DATE OF FIT_ACCOUNTING ------------*/
                /*------------------------------------------------------------------------------*/
                dao.updateStatusAndDate(Utility.searchListTechnicalIds(xxItem), Constants.STATUS_SEND);
 
                /*---------------------------------------*/
                /*-------------ADD A HISTORY ------------*/
                /*---------------------------------------*/
                dao.addTransactionHistoryByTechnicalIds(Utility.searchListTechnicalIds(xxItem), Constants.STATUS_SEND);
 
                throw new Exception();
 
            } catch (Exception e) {
                //if error, all data will fixe with status "error"
                log.error("Exception",e);
                dao.updateStatusAndDate(Utility.searchListTechnicalIds(xxItem), Constants.STATUS_ERROR);
 
                /*---------------------------------------*/
                /*-------------ADD A HISTORY ------------*/
                /*---------------------------------------*/
                dao.addTransactionHistoryByTechnicalIds(Utility.searchListTechnicalIds(xxItem), Constants.STATUS_ERROR);
            }
        }
    }
A votre avis, doit-on rajouter quelque chose dans un fichier de configuration ou une annotation ?

Là je ne vois pas du tout.

Pour info, pour mon DAO, j'utilise getSimpleJdbcTemplate().update

Merci d'avance pour votre aide.