OpenJPA
  1. OpenJPA
  2. OPENJPA-819

NPE when no metadata is defined for a persistent class

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0.0-M2
    • Fix Version/s: 2.0.0-M2
    • Component/s: kernel
    • Labels:
      None

      Description

      The persistent class was specified in the persistence.xml under <class>, but persistence metadata was not specified for the class, either through annotation or the orm.xml. A NPE was thrown. We need a better message.

      This issue was reported in the user forum by post http://n2.nabble.com/NullPointerException-when-calling-createEntityManager-on--EntityManagerFactory-td1621881.html

      1. OPENJPA-819.patch
        7 kB
        Dianne Richards
      2. OPENJPA-819.patch
        6 kB
        Dianne Richards

        Activity

        Hide
        Dianne Richards added a comment -

        Attaching patch for this problem. Please review and commit if ok.

        Show
        Dianne Richards added a comment - Attaching patch for this problem. Please review and commit if ok.
        Hide
        Dianne Richards added a comment -

        Pinaki responded with the following in the mailing list. I'm documenting here. Thanks Pinaki. See my embedded responses:

        1. Many error messages in OpenJPA not only tells what the error is, it also
        tries to help what can be common cause of the error. From that standpoint,
        the message
        no-meta: No registered metadata for type "

        {0}".
        could be changed to something like
        no-meta: No registered metadata for class "{0}

        ". This can happen if this
        class has not been annotated as persistent entity or specified in the
        persistence unit.

        <der>I agree. I just used an existing message. But, I'll update it as part of this fix.</der>

        2. The test case can benefit from deriving from SingleEMFTest case and its
        setUp(Object...args). There are many examples available in
        openjpa-persistence-jdbc test package on its usage.

        <der>Actually, I know about this class and I initially tried it. But, it went down a different path. It issued a similar message, but it did not go through the code that I changed. So, I had to resort to the current scheme.</der>

        3. If SingleEMFTestCase is used, persistence.xml is not needed.

        <der>See my comment under 2.</der>

        4. The comments just above where the new exception is raised should be
        modified, as after this change it sounds contradictory.

        <der>Will do</der>

        Show
        Dianne Richards added a comment - Pinaki responded with the following in the mailing list. I'm documenting here. Thanks Pinaki. See my embedded responses: 1. Many error messages in OpenJPA not only tells what the error is, it also tries to help what can be common cause of the error. From that standpoint, the message no-meta: No registered metadata for type " {0}". could be changed to something like no-meta: No registered metadata for class "{0} ". This can happen if this class has not been annotated as persistent entity or specified in the persistence unit. <der>I agree. I just used an existing message. But, I'll update it as part of this fix.</der> 2. The test case can benefit from deriving from SingleEMFTest case and its setUp(Object...args). There are many examples available in openjpa-persistence-jdbc test package on its usage. <der>Actually, I know about this class and I initially tried it. But, it went down a different path. It issued a similar message, but it did not go through the code that I changed. So, I had to resort to the current scheme.</der> 3. If SingleEMFTestCase is used, persistence.xml is not needed. <der>See my comment under 2.</der> 4. The comments just above where the new exception is raised should be modified, as after this change it sounds contradictory. <der>Will do</der>
        Hide
        Dianne Richards added a comment -

        Updated patch incorporating Pinaki's comments. Please review.

        Show
        Dianne Richards added a comment - Updated patch incorporating Pinaki's comments. Please review.
        Hide
        Jeremy Bauer added a comment -

        Committed for Dianne Richards to trunk under revision 727813. Resolving issue.

        Show
        Jeremy Bauer added a comment - Committed for Dianne Richards to trunk under revision 727813. Resolving issue.

          People

          • Assignee:
            Dianne Richards
            Reporter:
            Dianne Richards
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development