glassfish
  1. glassfish
  2. GLASSFISH-311

new assertion: PersistenceContext can not be injected into a web application

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 9.0pe
    • Fix Version/s: 9.0pe
    • Component/s: verifier
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      311

      Description

      Refer to
      http://weblogs.java.net/blog/ss141213/archive/2005/12/dont_use_persis_1.html
      where this issue is discussed.
      This is only applicable for servlets that follow multi-threaded model.
      One thing I would like to add is that although @PersistenceContext can not be
      used to inject an EntityManager, it can still be used to add an entry in the
      web application's JNDI namespace. e.g. this is allowed:

      @PersistenceContext(name="persistence/LogicalName", unitName="ActualName")
      public class MyServlet extends Servlet {
      public void service(...)

      { EntityManager pc = (EntityManager) new InitialContext().lookup("java:comp/env/persistence/LogicalName); ... }

      }

      but this is not allowed:
      public class MyServlet extends Servlet {
      @persistenceContext(unitName="ActualName") EntityManager em;
      public void service(...)

      { em.... }

      }

      1. 311.tar
        90 kB
        Bhavanishankar

        Activity

        Hide
        Bhavanishankar added a comment -

        Checking in LocalStrings.properties;
        /cvs/glassfish/avk/src/tools/com/sun/enterprise/tools/verifier/LocalStrings.properties,v
        <-- LocalStrings.properties
        new revision: 1.67; previous revision: 1.66
        done
        Checking in TestNamesApp.xml;
        /cvs/glassfish/avk/config/verifier/TestNamesApp.xml,v <-- TestNamesApp.xml
        new revision: 1.8; previous revision: 1.7
        done
        Checking in TestNamesAppClient.xml;
        /cvs/glassfish/avk/config/verifier/TestNamesAppClient.xml,v <--
        TestNamesAppClient.xml
        new revision: 1.12; previous revision: 1.11
        done
        Checking in TestNamesEjb.xml;
        /cvs/glassfish/avk/config/verifier/TestNamesEjb.xml,v <-- TestNamesEjb.xml
        new revision: 1.29; previous revision: 1.28
        done
        Checking in TestNamesWeb.xml;
        /cvs/glassfish/avk/config/verifier/TestNamesWeb.xml,v <-- TestNamesWeb.xml
        new revision: 1.12; previous revision: 1.11
        done
        RCS file:
        /cvs/glassfish/avk/src/tools/com/sun/enterprise/tools/verifier/tests/web/EntityManagerInjection.java,v
        done
        Checking in web/EntityManagerInjection.java;
        /cvs/glassfish/avk/src/tools/com/sun/enterprise/tools/verifier/tests/web/EntityManagerInjection.java,v
        <-- EntityManagerInjection.java
        initial revision: 1.1
        done

        Show
        Bhavanishankar added a comment - Checking in LocalStrings.properties; /cvs/glassfish/avk/src/tools/com/sun/enterprise/tools/verifier/LocalStrings.properties,v <-- LocalStrings.properties new revision: 1.67; previous revision: 1.66 done Checking in TestNamesApp.xml; /cvs/glassfish/avk/config/verifier/TestNamesApp.xml,v <-- TestNamesApp.xml new revision: 1.8; previous revision: 1.7 done Checking in TestNamesAppClient.xml; /cvs/glassfish/avk/config/verifier/TestNamesAppClient.xml,v <-- TestNamesAppClient.xml new revision: 1.12; previous revision: 1.11 done Checking in TestNamesEjb.xml; /cvs/glassfish/avk/config/verifier/TestNamesEjb.xml,v <-- TestNamesEjb.xml new revision: 1.29; previous revision: 1.28 done Checking in TestNamesWeb.xml; /cvs/glassfish/avk/config/verifier/TestNamesWeb.xml,v <-- TestNamesWeb.xml new revision: 1.12; previous revision: 1.11 done RCS file: /cvs/glassfish/avk/src/tools/com/sun/enterprise/tools/verifier/tests/web/EntityManagerInjection.java,v done Checking in web/EntityManagerInjection.java; /cvs/glassfish/avk/src/tools/com/sun/enterprise/tools/verifier/tests/web/EntityManagerInjection.java,v <-- EntityManagerInjection.java initial revision: 1.1 done
        Hide
        Bhavanishankar added a comment -

        Integrated in b40.

        Show
        Bhavanishankar added a comment - Integrated in b40.
        Hide
        Bhavanishankar added a comment -

        Created an attachment (id=103)
        testcase - 311/build/blog5.ear

        Show
        Bhavanishankar added a comment - Created an attachment (id=103) testcase - 311/build/blog5.ear
        Hide
        Bhavanishankar added a comment -

        Injecting a EntityManager or a stateful session bean into a servlet instance is
        not recommended because of the concurrency issues but the spec does not prohibit
        it. So, the verifier should treat this kind of findings as WARNINGs.

        Checking in LocalStrings.properties;
        /cvs/glassfish/avk/src/tools/com/sun/enterprise/tools/verifier/LocalStrings.properties,v
        <-- LocalStrings.properties
        new revision: 1.74; previous revision: 1.73
        done
        Checking in tests/web/EntityManagerInjection.java;
        /cvs/glassfish/avk/src/tools/com/sun/enterprise/tools/verifier/tests/web/EntityManagerInjection.java,v
        <-- EntityManagerInjection.java
        new revision: 1.2; previous revision: 1.1
        done

        Show
        Bhavanishankar added a comment - Injecting a EntityManager or a stateful session bean into a servlet instance is not recommended because of the concurrency issues but the spec does not prohibit it. So, the verifier should treat this kind of findings as WARNINGs. Checking in LocalStrings.properties; /cvs/glassfish/avk/src/tools/com/sun/enterprise/tools/verifier/LocalStrings.properties,v <-- LocalStrings.properties new revision: 1.74; previous revision: 1.73 done Checking in tests/web/EntityManagerInjection.java; /cvs/glassfish/avk/src/tools/com/sun/enterprise/tools/verifier/tests/web/EntityManagerInjection.java,v <-- EntityManagerInjection.java new revision: 1.2; previous revision: 1.1 done
        Hide
        Sanjeeb Sahoo added a comment -

        verified

        Show
        Sanjeeb Sahoo added a comment - verified

          People

          • Assignee:
            Bhavanishankar
            Reporter:
            Sanjeeb Sahoo
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: