OpenEJB
  1. OpenEJB
  2. OPENEJB-1443

EntityManager in non-transactional business methods using queries can be used only once

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.1.4
    • Fix Version/s: 4.0.0-beta-2
    • Component/s: integration
    • Labels:
      None

      Description

      A call without any transaction on a business method which does not require a transaction cannot use the EntityManager after making a query. The Query object is wrapped by JtaQuery which closes the EntityManager after any call to the object. The following is an example that does not work when called outside of any transaction, where em is the injected EntityManager:

      @TransactionAttribute(TransactionAttributeType.SUPPORTS)
      public City getCity(String cityName)

      { Query query = null; query = em.createNamedQuery("City.RetrieveCityByName"); query.setParameter(1, cityName); if (!query.getResultList().isEmpty()) --> return (City) query.getResultList().get(0); else throw new RuntimeException("Cannot locate a city named " + cityName); }

      The first call to getResultList() is OK, but the second call fails because it already closed the EntityManager. The following stack trace excerpt shows the stack in OpenEJB during the second call to getResultList():

      Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManager.
      at org.eclipse.persistence.internal.jpa.EntityManagerImpl.verifyOpen(EntityManagerImpl.java:1516)
      at org.eclipse.persistence.internal.jpa.EntityManagerImpl.close(EntityManagerImpl.java:1380)
      at org.apache.openejb.persistence.JtaQuery.getResultList(JtaQuery.java:45)

        Activity

        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Closed Closed
        262d 23h 1m 1 Romain Manni-Bucau 29/Nov/11 10:57
        Hide
        David Blevins added a comment -
        Show
        David Blevins added a comment - 2011-11-29 - http://svn.apache.org/viewvc?view=revision&revision=1207802 - rmannibucau
        Romain Manni-Bucau made changes -
        Field Original Value New Value
        Status Open [ 1 ] Closed [ 6 ]
        Fix Version/s 4.0-beta-2 [ 12318444 ]
        Resolution Fixed [ 1 ]
        Hide
        Romain Manni-Bucau added a comment -

        should be ok on trunk

        Show
        Romain Manni-Bucau added a comment - should be ok on trunk
        David Allen created issue -

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development