Thank you for your trick Andrus
But DataContext.invalidateObjects(failed) does not work because cayenne tries to recommit all the same objects
so I used dataContext.unregisterObjects();
But I have a duplicate primary key :-(
A snapshot of my code :


        try {
          dataContext.commitChanges();
        }
        catch (ValidationException e) {
logger.error("Cannot commit, trying to invalidate objects ?!", e);
          ValidationResult validationResult = e.getValidationResult();
          if (validationResult != null) {
            List failures = validationResult.getFailures();
            List failedObjects = new LinkedList();
            for (Object validationFailure : failures) {
failedObjects.add(((ValidationFailure) validationFailure).getSource());
            }
            dataContext.unregisterObjects(failedObjects);
            dataContext.commitChanges();
          }
        }

In this test the database was empty
an extract of the log :

2008-05-07 10:14:46,812 INFO [main] (QueryLogger.java:300) - INSERT INTO RDV (Absent, Adresse, Agent, Appel_Date, Appel_Heure, Appel_Timestamp, Argumentation, CommentairesTA, CommercialId, Controle, ExchangeId, Id, Mobile, Nom, Presentation, Prix, RDV_Date, RDV_Heure, RDV_Timestamp, Refus, RemarquesCommercial, Report, StatutMadame, StatutMonsieur, Telephone, TypeArgumentation, Vente) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 2008-05-07 10:14:46,812 INFO [main] (QueryLogger.java:322) - [bind: 'non', '1344 ROUTE DE VERMEIL 30380 ST CHRISTOL LES ALES', 'Claudine (cbrunet)', '2008-03-06 09:30:00.0', '2008-03-06 09:30:00.0', 1204792200000, 'non', 'portail bleu en retrait de la route a 100m de la route de montpellier', 201, 'non', '1204707505208', 200, NULL, 'Dulaurent Jean-Michel', 'oui', 0, '2008-03-06 09:30:00.0', '2008-03-06 09:30:00.0', 1204792200000, 'non', 'dejà vu l''année derniere pro control,ne fera jamais rien', 'non', NULL, NULL, '33466832655', NULL, 'non'] 2008-05-07 10:14:46,843 INFO [main] (QueryLogger.java:368) - === updated 1 row.

--> this row was saved in db with id 200


2008-05-07 10:14:46,875 ERROR [main] (Main.java:257) - Cannot commit, trying to invalidate objects ?! org.apache.cayenne.validation.ValidationException: [v.2.0.4 October 8 2007] Validation has failed. Validation failure for fr.c3t.aeh.entity.dao.Rdv.absent: "absent" exceeds maximum allowed length (3 chars): 11 at org.apache.cayenne.access.ObjectStoreGraphDiff.validateAndCheckNoop(ObjectStoreGraphDiff.java:112) at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1217) at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:1138)
        at fr.c3t.aeh.Main.getRDV(Main.java:254)
        at fr.c3t.aeh.Main.extract(Main.java:161)
        at fr.c3t.aeh.Main.testGetRDV(Main.java:134)
        at fr.c3t.aeh.Main.main(Main.java:121)

--> it was the first object unregistered


2008-05-07 10:14:46,890 ERROR [main] (Main.java:257) - Cannot commit, trying to invalidate objects ?! org.apache.cayenne.validation.ValidationException: [v.2.0.4 October 8 2007] Validation has failed. Validation failure for fr.c3t.aeh.entity.dao.Rdv.vente: "vente" exceeds maximum allowed length (3 chars): 13 at org.apache.cayenne.access.ObjectStoreGraphDiff.validateAndCheckNoop(ObjectStoreGraphDiff.java:112) at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1217) at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:1138)
        at fr.c3t.aeh.Main.getRDV(Main.java:254)
        at fr.c3t.aeh.Main.extract(Main.java:161)
        at fr.c3t.aeh.Main.testGetRDV(Main.java:134)
        at fr.c3t.aeh.Main.main(Main.java:121)

--> it was the second object unregistered

2008-05-07 10:14:46,921 INFO [main] (QueryLogger.java:300) - INSERT INTO RDV (Absent, Adresse, Agent, Appel_Date, Appel_Heure, Appel_Timestamp, Argumentation, CommentairesTA, CommercialId, Controle, ExchangeId, Id, Mobile, Nom, Presentation, Prix, RDV_Date, RDV_Heure, RDV_Timestamp, Refus, RemarquesCommercial, Report, StatutMadame, StatutMonsieur, Telephone, TypeArgumentation, Vente) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 2008-05-07 10:14:46,937 INFO [main] (QueryLogger.java:322) - [bind: 'non', '28 CHEMIN DES TOURETTES 30340 MEJANNES LES ALES', 'Sabrina (skara)', '2008-03-05 16:00:00.0', '2008-03-05 16:00:00.0', 1204729200000, 'oui', 'A coté de l''ancienne mairie,portail gris', 201, 'oui', '1204537791936', 200, NULL, 'Brodure Serge', 'oui', 6000, '2008-03-05 16:00:00.0', '2008-03-05 16:00:00.0', 1204729200000, 'non', 'bon rdv', 'non', NULL, NULL, '33466603463', NULL, 'oui']
2008-05-07 10:14:46,953 INFO  [main] (QueryLogger.java:403) - *** error.
java.sql.SQLException: Duplicate key or integrity constraint violation message from server: "Duplicate entry '200' for key 1"
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2001)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1168)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1279)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2281)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1825) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1667) at org.apache.cayenne.access.jdbc.BatchAction.runAsIndividualQueries(BatchAction.java:188) at org.apache.cayenne.access.jdbc.BatchAction.performAction(BatchAction.java:81) at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:59)
        at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:273)
at org.apache.cayenne.access.DataDomainFlushAction.runQueries(DataDomainFlushAction.java:219) at org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:141)
        at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:810)
        at org.apache.cayenne.access.DataDomain$2.transform(DataDomain.java:781)
at org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:836)
        at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:778)
at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1234) at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:1138)
        at fr.c3t.aeh.Main.getRDV(Main.java:254)
        at fr.c3t.aeh.Main.extract(Main.java:161)
        at fr.c3t.aeh.Main.testGetRDV(Main.java:134)
        at fr.c3t.aeh.Main.main(Main.java:121)

Finally this third object was valid but Cayenne used the same Id.

Sincerely,
Julien

Reply via email to