OpenJPA
  1. OpenJPA
  2. OPENJPA-2155

Transaction Management in multiple Entities in one transaction

    Details

    • Type: Question Question
    • Status: Closed
    • Priority: Major Major
    • Resolution: Not a Problem
    • Affects Version/s: 2.1.1
    • Fix Version/s: None
    • Component/s: jpa
    • Labels:
    • Environment:
      WebSphere Application Server 6.1.37 on Windows and AIX

      Description

      I am a new user on OpenJPA,
      I have a scenario where I need to perform update/insert in multiple entities on one transaction. How to achieve this?

      example of EntityManager update method (auto generated by Rational Software Architect8.0.3). [ The same way, I have two more entities. ]
      ==================
      @Action(Action.ACTION_TYPE.UPDATE)
      public String updateKna1(Kna1 kna1) throws Exception {
      EntityManager em = getEntityManager();
      try

      { em.getTransaction().begin(); kna1 = em.merge(kna1); em.getTransaction().commit(); }

      catch (Exception ex) {
      try {
      if (em.getTransaction().isActive())

      { em.getTransaction().rollback(); }

      } catch (Exception e)

      { ex.printStackTrace(); throw e; }

      throw ex;
      } finally

      { ////em.close(); }

      return "";
      }

      ==========================
      If I keep commit/rollback in each entity then I can not rollback from all previous entities (if last entity insert or update fails).

      Can you help me on this?

      Thanks in Advance.

        Activity

          People

          • Assignee:
            Unassigned
            Reporter:
            Prabhat
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development