castor
  1. castor
  2. CASTOR-1044

Delete and the insert with same id in the same transaction fails

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 0.9.6
    • Fix Version/s: 1.3.3rc1
    • Component/s: JDO
    • Labels:
      None
    • Environment:
      Operating System: Windows XP
      Platform: PC
    • Bugzilla Id:
      1907
    • Number of attachments :
      3

      Description

      I need to delete all in a DB related to a pk and then insert new data with the
      same pk inside the same transaction. Even if Oracle supports this feature,
      Castor don't let me do it. I read JDO FAQ at Castor's website and I found that:

      "Can an object with the same identity be re-created after being removed in the
      same transaction?

      Yes, as long as the deleted object is the same instance as the one being recreated."

      So, I try to do this and did not work. Here is the test-code that I've used:

      public class Job_XF {

      public static void execute( java.util.Hashtable variables ) {

      try {

      JDO jdo = new JDO("fomentola");
      jdo.loadConfiguration(
      (Job_XF.class).getResource("/connection.xml").toString() );
      Database db = jdo.getDatabase();

      db.begin();
      co.gov.colciencias.interscienti.fomentola.En_producao_cientif_tecnol
      rhF =
      (co.gov.colciencias.interscienti.fomentola.En_producao_cientif_tecnol)db.load(
      co.gov.colciencias.interscienti.fomentola.En_producao_cientif_tecnol.class, new
      Complex( new Object[]

      {new java.math.BigDecimal("29918"),"0000283878"}

      ) );
      db.remove(rhF);
      db.create(rhF);
      db.commit();
      db.close();

      } catch(Exception e)

      { e.printStackTrace(); }

      }
      }

      After execution this is the Exception stack:

      org.exolab.castor.jdo.DuplicateIdentityException: Duplicate identity found for
      object of type
      co.gov.colciencias.interscienti.fomentola.En_producao_cientif_tecnol with
      identity <29918(927458),0000283878(1484588876)>: an object with the same
      identity already exists in persistent storage
      at org.exolab.castor.persist.LockEngine.create(LockEngine.java:469)
      at
      org.exolab.castor.persist.TransactionContext.create(TransactionContext.java:941)
      at org.exolab.castor.jdo.engine.DatabaseImpl.create(DatabaseImpl.java:380)
      at config.projects.cvlac.scripts.Job_XF.execute(Job_XF.java:19)
      at
      config.projects.cvlac.scripts.Job_CanBeDeleted.main(Job_CanBeDeleted.java:29)

      1. patch-C1044-20110626-1.txt
        5 kB
        Wensheng Dou
      2. patch-C1044-20110626-2.txt
        1 kB
        Wensheng Dou
      3. patch-C1044-20110701.txt
        15 kB
        Ralf Joachim

        Activity

        Hide
        Werner Guttmann added a comment -

        Arturo, can you please confirm that the problem you reported is still an issue ? If not, I'd like to mark this issue as resolved as discussed above.

        Show
        Werner Guttmann added a comment - Arturo, can you please confirm that the problem you reported is still an issue ? If not, I'd like to mark this issue as resolved as discussed above.
        Hide
        Ralf Joachim added a comment -

        I think we should go the save way here and test it.

        Show
        Ralf Joachim added a comment - I think we should go the save way here and test it.
        Hide
        Wensheng Dou added a comment -

        In patch-C1044-20110626-1.txt, I have added a test for this bug.

        Show
        Wensheng Dou added a comment - In patch-C1044-20110626-1.txt, I have added a test for this bug.
        Hide
        Wensheng Dou added a comment -

        After investigating the AbstractTransactionContext.markCreate, I think the code is wrong, If the uncommented code is executed, then the ObjectTrack.unMarkDeleted will not be executed. So I provided the patch which will repair the bug (patch-C1044-20110626-2.txt).

        Show
        Wensheng Dou added a comment - After investigating the AbstractTransactionContext.markCreate, I think the code is wrong, If the uncommented code is executed, then the ObjectTrack.unMarkDeleted will not be executed. So I provided the patch which will repair the bug (patch-C1044-20110626-2.txt).
        Hide
        Ralf Joachim added a comment -

        Merged both patches together, tested against derby, hsql, mysql, oracle, postgresql and updated CTF-Matrix

        Show
        Ralf Joachim added a comment - Merged both patches together, tested against derby, hsql, mysql, oracle, postgresql and updated CTF-Matrix

          People

          • Assignee:
            Wensheng Dou
            Reporter:
            Arturo C. Preda
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: