Topic
9 replies Latest Post - ‏2012-06-14T19:04:27Z by sutter
Cornell
Cornell
5 Posts
ACCEPTED ANSWER

Pinned topic NoSuchMethodError - pcGetIDOwningClass

‏2012-06-12T14:00:32Z |
When I upgraded OpenJPA from 1.2 to 2.0 by installing WebSphere OSGi/JPA 2.0 Feature Pack (1.0.0.7), I run into the following error. This error only occurs the first time (one time only) whenever the server is restarted. It seems that this issue may be related to OpenJPA enhancement initialization. Greatly appreciate for any suggestion about how to resolve this issue. Thanks!

6/12/12 9:45:46:174 EDT 0000001e BusinessExcep E CNTR0020E: EJB threw an unexpected (non-declared) exception during invocation of method "findWithNamedQuery" on bean "BeanId(MYEAR#MYEJB.jar#PersistenceServiceImpl, null)". Exception data: java.lang.NoSuchMethodError: com/xxx/xxx/entity/MyClass.pcGetIDOwningClass()Ljava/lang/Class;
at com.xxx.xxx.entity.MyClass.pcNewObjectIdInstance(MyClass.java)
at org.apache.openjpa.enhance.PCRegistry.newObjectId(PCRegistry.java:137)
at org.apache.openjpa.meta.MetaDataRepository.processRegisteredClass(MetaDataRepository.java:1661)
at org.apache.openjpa.meta.MetaDataRepository.processRegisteredClasses(MetaDataRepository.java:1615)
at org.apache.openjpa.meta.ClassMetaData.getPCSubclasses(ClassMetaData.java:365)
at org.apache.openjpa.jdbc.meta.MappingRepository.findBaseClassMapping(MappingRepository.java:1510)
at org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRepository.java:403)
at org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository.java:736)
at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:625)
at org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataRepository.java:385)
at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:358)
at org.apache.openjpa.meta.MetaDataRepository.resolveAll(MetaDataRepository.java:1923)
at org.apache.openjpa.meta.MetaDataRepository.getQueryMetaDataInternal(MetaDataRepository.java:1901)
at org.apache.openjpa.meta.MetaDataRepository.getQueryMetaData(MetaDataRepository.java:1888)
at org.apache.openjpa.persistence.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1013)
at com.ibm.ws.persistence.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:69)
at com.ibm.ws.persistence.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:29)
at com.ibm.ws.jpa.management.JPATxEmInvocation.createNamedQuery(JPATxEmInvocation.java:123)
at com.ibm.ws.jpa.management.JPAEntityManager.createNamedQuery(JPAEntityManager.java:332)
Updated on 2012-06-14T19:04:27Z at 2012-06-14T19:04:27Z by sutter
  • sutter
    sutter
    94 Posts
    ACCEPTED ANSWER

    Re: NoSuchMethodError - pcGetIDOwningClass

    ‏2012-06-13T19:55:31Z  in response to Cornell
    Hi Cornell,
    Your intuition looks accurate. The pcGetIDOwningClass is a method that is introduced as part of the enhancement processing. It looks like this query is being executed before that Entity class is referenced. To get a "real" solution, I would suggest creating a PMR. Either this issue has already been resolved (and a fix is already available), or it should be... :-)

    In the mean time, you've got a couple of options. One is to reference the MyClass Entity before executing this query. Just something simple that would load the MyClass class before the query attempts to access it. Or, you could enhance your entities at build time, but this might be a bit more work.

    Good luck,
    Kevin Sutter, JPA Architect, IBM WebSphere
    • Cornell
      Cornell
      5 Posts
      ACCEPTED ANSWER

      Re: NoSuchMethodError - pcGetIDOwningClass

      ‏2012-06-13T20:19:08Z  in response to sutter
      Hi Kevin,

      Many thanks for your reply.

      I have encountered this same error in both WebSphere Feature Pack JPA 2.0 1.0.0.5/1.0.0.7 fixpacks. It does not seem that there were many posts about this issue when I did some googling. I would have hoped to see some if an IBM PMR was filed and resolved previously.

      If I understand correctly, IBM JPA provider explicity disables the RuntimeUnenhancedClasses capability of OpenJPA due to several issues associated with that feature. Since my application is running within a managed application server environment, I assume that the enhancement is done automatically when the entity classes are first loaded by the Container's classloader. There is a specification-defined hook that allows the JPA enhancement plugin to get called during the classloading process. Thus, I do not fully understand why I would have to enhance my entities at build time in this case.

      Thanks for your help.
      • sutter
        sutter
        94 Posts
        ACCEPTED ANSWER

        Re: NoSuchMethodError - pcGetIDOwningClass

        ‏2012-06-13T21:45:58Z  in response to Cornell
        Hi Cornell,
        You are absolutely correct. You should not be expected to do build-time enhancement (nor do the Entity class touch). I was only offering those suggestions as work-arounds until your eventual PMR is addressed.

        BTW, another work-around that will actually help with performance is to use the following property in your persistence.xml:

        <property name="openjpa.MetaDataRepository" value="Preload=true"/>

        This does require all of your Entity classes to be listed in your persistence.xml file via the <class>..</class> attributes. But, in the end, this will ensure that your Entity classes are enhanced and the MetaDataRepository (internal data structure) can process without locking for better performance and scalability.

        Just trying to help...
        Kevin Sutter, JPA Architect, IBM WebSphere
        • Cornell
          Cornell
          5 Posts
          ACCEPTED ANSWER

          Re: NoSuchMethodError - pcGetIDOwningClass

          ‏2012-06-14T11:42:58Z  in response to sutter
          Many thanks for the reply.

          I had tried to add the following generic JVM argument to my WAS:
          -javaagent:"${was_home}/runtimes/base_v7/feature_packs/jpa/runtimes/com.ibm.ws.jpa.thinclient_JPA2FEP1.0.0.jar"
          but it did not seem making any difference in this case. I just wonder if I picked the wrong JAR file from IBM's JPA package or I did something wrong with this approach.

          Please advise.
          • sutter
            sutter
            94 Posts
            ACCEPTED ANSWER

            Re: NoSuchMethodError - pcGetIDOwningClass

            ‏2012-06-14T13:16:54Z  in response to Cornell
            Hi Cornell,
            I just took a closer look at your original message and I don't think this is an issue with missing the enhancement process. If you notice, the caller of this missing MyClass.pcGetIDOwningClass() method is MyClass.pcNewObjectIdInstance(), which is also a method introduced by enhancement. So, your Entity class has been enhanced. It's just missing this pcGetIDOwningClass() method implementation for some reason.

            A quick look at the code indicates that this method is generated when the PK (Id) is abstract or contains abstract fields. The calling of this generated method also seems to be dependent on these conditions. So, there must be an issue with either how your PK is defined or how the JPA code is interpretting the mapping.

            Now that I think we're getting closer to the root cause, I would suggest opening a PMR and providing your Entity definitions as well as your persistence.xml. Mention in the PMR that this problem has been discussed on this forum and that it should go directly to the JPA L3 queue. Thanks!

            Kevin Sutter, JPA Architect, IBM WebSphere
            • Cornell
              Cornell
              5 Posts
              ACCEPTED ANSWER

              Re: NoSuchMethodError - pcGetIDOwningClass

              ‏2012-06-14T15:28:47Z  in response to sutter
              Thanks again for the reply.

              If there must be an issue with either how my PK is defined or how the JPA code is interpretting the mapping, I would think that I should run into the same error the second time, or say, all the times. But the pattern here is that this error only occurs the first time (i.e. one time only) whenever my server is restarted.

              Any thoughts?
              • sutter
                sutter
                94 Posts
                ACCEPTED ANSWER

                Re: NoSuchMethodError - pcGetIDOwningClass

                ‏2012-06-14T16:28:10Z  in response to Cornell
                Hi Cornell,
                Sure, lots of thoughts... Just not sure which ones apply to this scenario... :-)

                Here's my guess... Since this Query is the first time accessing the MetaDataRepository (MDR) for this particular Entity, we go down a certain path that requires the existence of this method. But, after this initial Query, the MDR processing no longer requires this particular path to accomplish it's goals and, thus, avoids the requirement for this method.

                Since the Entity has already been enhanced, the JPA code does not perform any "re-enhancement". So, the enhanced Entity still does not have this "missing" method on the 2nd, 3rd, or later accesses. But, due to other runtime processing, it's not required on these later 2nd, 3rd, etc accesses.

                That's my guess and I'm sticking to it... :-)

                Kevin Sutter, JPA Architect, IBM WebSphere
                • Cornell
                  Cornell
                  5 Posts
                  ACCEPTED ANSWER

                  Re: NoSuchMethodError - pcGetIDOwningClass

                  ‏2012-06-14T18:40:04Z  in response to sutter
                  Thanks for the reply again.

                  Two more observations that I would like to add to this puzzle.
                  1) The query which generates this error actually has nothing to do with this particular entity, MyClass, in this case. In other words, I would run into the same error stack trace (the top section part) of this same entity, MyClass, even with other queries, as long as it is the first query to be executed for the same app.
                  2) The exact same app with no code change would run without this error before my JPA upgrade to 2.0 (i.e. before installing WebSphere JPA 2.0 Feature Pack).

                  So far I am still looking for evidence if this particular entity, MyClass, is the root cause of the encountered error.
                  • sutter
                    sutter
                    94 Posts
                    ACCEPTED ANSWER

                    Re: NoSuchMethodError - pcGetIDOwningClass

                    ‏2012-06-14T19:04:27Z  in response to Cornell
                    Care to provide your MyClass entity class and your persistence.xml? If MyClass has relationships to other types, those would be good as well.

                    Thanks,
                    Kevin Sutter, JPA Architect, IBM WebSphere