2 Replies Latest reply: Feb 11, 2014 2:12 PM by Tom Henricksen RSS

    TopLink not saving

    Tom Henricksen

      We are using TopLink 9.0.3.7 in our Java application. I have recently added two new tables I am trying to save to. I am comparing this to some similar tables that save correctly and everything appears to be the same. I have compared the descriptors created by TopLink Mappling WorkBench 9.0.3.5 and they appear the same too.

      From our Action class

      submissionDao.transaction(sessionInfo.getClerkReviewSubmission(),
        new TransactionBlock<ClerkReviewSubmission>() {
        public void merge(ClerkReviewSubmission detached,
        ClerkReviewSubmission managed) {

        ClerkReviewTask task = mergeTask(new ClerkReviewTask(),
        myForm);
        for(ClerkReviewCase crCase: sessionInfo.getClerkReviewSubmission().getCases()){
        createCaseTask(crCase, task);
        }
        }
        });

        private final ClerkReviewCaseTask createCaseTask(ClerkReviewCase crCase,
        ClerkReviewTask task) {
        ClerkReviewCaseTask caseTask = new ClerkReviewCaseTask();
        caseTask.setClerkReviewCase(crCase);
        caseTask.setTask(task);
        crCase.getCaseTasks().add(caseTask);
        task.getCaseTasks().add(caseTask);
        return caseTask;
        }

      From our BaseDAO class

      public T transaction(T detached, TransactionBlock transactionBlock) throws BadDBConnection {
        Session session = centralSourceInjector.inject();
        UnitOfWork uow = session.acquireUnitOfWork();

        try {
        T managed = (T)uow.registerObject((T) detached);
        transactionBlock.merge(detached, managed);

        uow.commit();
        session.refreshObject(detached);
        return managed;
        } catch(OptimisticLockException ole){
        uow.rollbackTransaction();
        throw ole;
        } finally {
        uow.release();
        }
      }

      When I debug I am reaching into the BaseDAO class and all I see in the logs are:

      UnitOfWork(3889394)--begin unit of work commit

      ClientSession(5022219)--Connection(7034305)--begin transaction

      ClientSession(5022219)--Connection(7034305)--commit transaction

      UnitOfWork(3889394)--end unit of work commit

      UnitOfWork(3889394)--release unit of work

      Any Suggestions or guidance would be appreciated.

        • 1. Re: TopLink not saving
          cdelahun

          The code is probably incomplete, but the ClerkReviewSubmission managed you pass into the TransactionBlock's merge method isn't used.  Everything you do within that method seems to be on unregistered objects, so there is no way for TopLink to see that anything has changed.  Did you mean to use the passed in'managed ClerkReviewSubmissioninstead of sessionInfo.getClerkReviewSubmission() within the for loop?

          • 2. Re: TopLink not saving
            Tom Henricksen

            A co-worker reviewed my code and suggested I add one additional line and it fixed the problem. He suggested a small change in my Action class:

            submissionDao.transaction(sessionInfo.getClerkReviewSubmission(),

                 new TransactionBlock<ClerkReviewSubmission>() {

                      public void merge(ClerkReviewSubmission detached,

                           ClerkReviewSubmission managed) {

                        ClerkReviewTask task = mergeTask(new ClerkReviewTask(), myForm);

                        for (ClerkReviewCase crCase : sessionInfo .getClerkReviewSubmission().getCases()) {

                           ClerkReviewCase crCase2 = managed.findCase(crCase .getIcisCaseId());

                           createCaseTask(crCase2, task);

                         }

                      }

                 });

            }

            Thanks

             

            Message was edited by: 902417ef-fc95-42da-b864-78d44119c9bc correct code formatting