You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cayenne.apache.org by Lasantha Ranaweera <la...@opensource.lk> on 2007/02/27 15:37:45 UTC

Caynne with Geronimo NPE

Hi All,

Finally I could managed to figure out the class loading problem with the
help of Andrus comment. Now we are almost there for Geronimo Cayenne
integration and having a NPE in Cayenne side when I am deploying a sample
given in the Geronimo testsuite. :)

I have given error, Java class file & the persistence xml below. Think it
is due to a one of these given files. Can somebody figure it out directly
& let me know what is there anything missing here? (hope it is not a
problem in Cayenne) :)

BTW as a solution I changed the given lines in EntityMapLoader class, then
it goes bit further and failed in Visitor classes again.

ClassLoader loader = context.getTempClassLoader(); //caynne existing one
ClassLoader loader = persistenceUnit.getClassLoader(); //my soultion since
we need to pass class loader from G side

Does both given lines will give exact same results from Cayenne side?

Error :=>
org.apache.cayenne.jpa.JpaProviderException: Error loading ORM descriptors
        at
org.apache.cayenne.jpa.conf.EntityMapLoader.loadEntityMap(EntityMapLoader.java:105)
        at
org.apache.cayenne.jpa.conf.EntityMapLoader.<init>(EntityMapLoader.java:77)
        at
org.apache.cayenne.jpa.Provider.createContainerEntityManagerFactory(Provider.java:222)
        at
org.apache.geronimo.persistence.PersistenceUnitGBean.<init>(PersistenceUnitGBean.java:98)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
        at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
        at
org.apache.geronimo.gbean.runtime.GBeanInstance.createInstance(GBeanInstance.java:936)
        at
org.apache.geronimo.gbean.runtime.GBeanInstanceState.attemptFullStart(GBeanInstanceState.java:267)
        at
org.apache.geronimo.gbean.runtime.GBeanInstanceState.start(GBeanInstanceState.java:102)
        at
org.apache.geronimo.gbean.runtime.GBeanInstanceState.startRecursive(GBeanInstanceState.java:124)
        at
org.apache.geronimo.gbean.runtime.GBeanInstance.startRecursive(GBeanInstance.java:543)
        at
org.apache.geronimo.kernel.basic.BasicKernel.startRecursiveGBean(BasicKernel.java:379)
        at
org.apache.geronimo.kernel.config.ConfigurationUtil.startConfigurationGBeans(ConfigurationUtil.java:434)
        at
org.apache.geronimo.kernel.config.KernelConfigurationManager.start(KernelConfigurationManager.java:188)
        at
org.apache.geronimo.kernel.config.SimpleConfigurationManager.startConfiguration(SimpleConfigurationManager.java:527)
        at
org.apache.geronimo.kernel.config.SimpleConfigurationManager.startConfiguration(SimpleConfigurationManager.java:508)
        at
org.apache.geronimo.kernel.config.SimpleConfigurationManager$$FastClassByCGLIB$$ce77a924.invoke(<generated>)
        at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53)
        at
org.apache.geronimo.gbean.runtime.FastMethodInvoker.invoke(FastMethodInvoker.java:38)
        at
org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(GBeanOperation.java:127)
        at
org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(GBeanInstance.java:820)
        at
org.apache.geronimo.gbean.runtime.RawInvoker.invoke(RawInvoker.java:57)
        at
org.apache.geronimo.kernel.basic.RawOperationInvoker.invoke(RawOperationInvoker.java:35)
        at
org.apache.geronimo.kernel.basic.ProxyMethodInterceptor.intercept(ProxyMethodInterceptor.java:96)
        at
org.apache.geronimo.kernel.config.EditableConfigurationManager$$EnhancerByCGLIB$$4e66e01d.startConfiguration(<generated>)
        at
org.apache.geronimo.deployment.plugin.local.StartCommand.run(StartCommand.java:67)
        at java.lang.Thread.run(Thread.java:595)
Caused by: java.lang.NullPointerException
        at
org.apache.cayenne.jpa.conf.ClassAnnotationProcessorFactory$EntityProcessor.onStartElement(ClassAnnotationProcessorFactory.java:85)
        at
org.apache.cayenne.jpa.conf.EntityMapAnnotationLoader.loadClassMapping(EntityMapAnnotationLoader.java:202)
        at
org.apache.cayenne.jpa.conf.EntityMapLoader.loadFromAnnotations(EntityMapLoader.java:195)
        at
org.apache.cayenne.jpa.conf.EntityMapLoader.loadEntityMap(EntityMapLoader.java:97)
        ... 28 more

Java File :=>
package org.apache.geronimo.itest.jpa;


import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Entity;

@Entity
public class AllFieldTypes {

    private short shortField;
    private int intField;
    private boolean booleanField;
    private long longField;
    private float floatField;
    private char charField;
    private double doubleField;
    private byte byteField;
    private String stringField;
    private Date dateField;
    private Set<String> setOfStrings = new HashSet<String>();
    private String[] arrayOfStrings;

    public void setShortField(short shortField) {
        this.shortField = shortField;
    }

    public short getShortField() {
        return this.shortField;
    }

    public void setIntField(int intField) {
        this.intField = intField;
    }

    public int getIntField() {
        return this.intField;
    }

    public void setBooleanField(boolean booleanField) {
        this.booleanField = booleanField;
    }

    public boolean getBooleanField() {
        return this.booleanField;
    }

    public void setLongField(long longField) {
        this.longField = longField;
    }

    public long getLongField() {
        return this.longField;
    }

    public void setFloatField(float floatField) {
        this.floatField = floatField;
    }

    public float getFloatField() {
        return this.floatField;
    }

    public void setCharField(char charField) {
        this.charField = charField;
    }

    public char getCharField() {
        return this.charField;
    }

    public void setDoubleField(double doubleField) {
        this.doubleField = doubleField;
    }

    public double getDoubleField() {
        return this.doubleField;
    }

    public void setByteField(byte byteField) {
        this.byteField = byteField;
    }

    public byte getByteField() {
        return this.byteField;
    }

    public void setStringField(String stringField) {
        this.stringField = stringField;
    }

    public String getStringField() {
        return this.stringField;
    }

    public void setDateField(Date dateField) {
        this.dateField = dateField;
    }

    public Date getDateField() {
        return this.dateField;
    }

    public void setSetOfStrings(Set<String> setOfStrings) {
        this.setOfStrings = setOfStrings;
    }

    public Set<String> getSetOfStrings() {
        return this.setOfStrings;
    }

    public void setArrayOfStrings(String[] arrayOfStrings) {
        this.arrayOfStrings = arrayOfStrings;
    }

    public String[] getArrayOfStrings() {
        return this.arrayOfStrings;
    }
}

persitence.xml =>

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">

    <persistence-unit transaction-type="RESOURCE_LOCAL" name="openjpa-itest">
        <provider>org.apache.cayenne.jpa.Provider</provider>
        <class>org.apache.geronimo.itest.jpa.AllFieldTypes</class>
        <exclude-unlisted-classes/>
    </persistence-unit>
</persistence>


Thanks,
Lasantha Ranaweera




Re: Caynne with Geronimo NPE

Posted by Andrus Adamchik <an...@objectstyle.org>.
> May be you can participate the discussions too. ;)

I will at least watch it - I am on Geronimo dev list.

Andrus


On Feb 27, 2007, at 6:54 PM, Lasantha Ranaweera wrote:

> Thanks Andrus for your explanation... I will investigate this more  
> bit &
> create a patch pretty soon. We will try to get some help from Geronimo
> side too. May be you can participate the discussions too. ;)
>
> Thanks,
> Lasantha
>
>>
>> On Feb 27, 2007, at 4:37 PM, Lasantha Ranaweera wrote:
>>
>>
>>> BTW as a solution I changed the given lines in EntityMapLoader
>>> class, then
>>> it goes bit further and failed in Visitor classes again.
>>>
>>> ClassLoader loader = context.getTempClassLoader(); //caynne
>>> existing one
>>> ClassLoader loader = persistenceUnit.getClassLoader(); //my
>>> soultion since
>>
>> We can't use the unit main ClassLoader at the point of loading the
>> annotations, as annotations processing predates class enhancement,
>> and we can't pollute the main class loader with unenhanced classes.
>>
>>
>>> Caused by: java.lang.NullPointerException
>>>         at
>>> org.apache.cayenne.jpa.conf.ClassAnnotationProcessorFactory
>>> $EntityProcessor.onStartElement
>>> (ClassAnnotationProcessorFactory.java:85)
>>>         at
>>> org.apache.cayenne.jpa.conf.EntityMapAnnotationLoader.loadClassMappi 
>>> ng
>>> (EntityMapAnnotationLoader.java:202)
>>>         at
>>> org.apache.cayenne.jpa.conf.EntityMapLoader.loadFromAnnotations
>>> (EntityMapLoader.java:195)
>>>         at
>>> org.apache.cayenne.jpa.conf.EntityMapLoader.loadEntityMap
>>> (EntityMapLoader.java:97)
>>>         ... 28 more
>>
>>
>> I assume there is a line mismatch, and the NPE is really at line 84,
>> so "element.getAnnotation(Entity.class)" returns null:
>>
>>         public void onStartElement(
>>                  AnnotatedElement element,
>>                  AnnotationProcessorStack context) {
>>              Entity entityAnnotation = element.getAnnotation
>> (Entity.class);
>>
>>              JpaEntity entity = new JpaEntity();
>>              entity.setClassName(((Class) element).getName());
>>              entity.setAttributes(new JpaAttributes());
>>
>>              if (!Util.isEmptyString(entityAnnotation.name()))
>> {      // LINE 84
>>                  entity.setName(entityAnnotation.name
>> ());             // LINE 85
>>              }
>>
>>              context.push(entity);
>>          }
>>
>> OpenEJB TemporaryClassLoader has this code that I suspect may causes
>> this error?? (I can't confirm it - it works in my OpenEJB integration
>> test environment):
>>
>>          // Annotation classes must be loaded by the normal  
>> classloader
>>          if (isAnnotationClass(bytes)) {
>>              return Class.forName(name, resolve, getClass
>> ().getClassLoader());
>>          }
>>
>> While the bug may still be on Cayenne end, I wonder if Dain or
>> somebody else from Geronimo can comment on this?
>>
>> Andrus
>>
>
>


Re: Caynne with Geronimo NPE

Posted by Lasantha Ranaweera <la...@opensource.lk>.
Thanks Andrus for your explanation... I will investigate this more bit &
create a patch pretty soon. We will try to get some help from Geronimo
side too. May be you can participate the discussions too. ;)

Thanks,
Lasantha

>
> On Feb 27, 2007, at 4:37 PM, Lasantha Ranaweera wrote:
>
>
>> BTW as a solution I changed the given lines in EntityMapLoader
>> class, then
>> it goes bit further and failed in Visitor classes again.
>>
>> ClassLoader loader = context.getTempClassLoader(); //caynne
>> existing one
>> ClassLoader loader = persistenceUnit.getClassLoader(); //my
>> soultion since
>
> We can't use the unit main ClassLoader at the point of loading the
> annotations, as annotations processing predates class enhancement,
> and we can't pollute the main class loader with unenhanced classes.
>
>
>> Caused by: java.lang.NullPointerException
>>         at
>> org.apache.cayenne.jpa.conf.ClassAnnotationProcessorFactory
>> $EntityProcessor.onStartElement
>> (ClassAnnotationProcessorFactory.java:85)
>>         at
>> org.apache.cayenne.jpa.conf.EntityMapAnnotationLoader.loadClassMapping
>> (EntityMapAnnotationLoader.java:202)
>>         at
>> org.apache.cayenne.jpa.conf.EntityMapLoader.loadFromAnnotations
>> (EntityMapLoader.java:195)
>>         at
>> org.apache.cayenne.jpa.conf.EntityMapLoader.loadEntityMap
>> (EntityMapLoader.java:97)
>>         ... 28 more
>
>
> I assume there is a line mismatch, and the NPE is really at line 84,
> so "element.getAnnotation(Entity.class)" returns null:
>
>         public void onStartElement(
>                  AnnotatedElement element,
>                  AnnotationProcessorStack context) {
>              Entity entityAnnotation = element.getAnnotation
> (Entity.class);
>
>              JpaEntity entity = new JpaEntity();
>              entity.setClassName(((Class) element).getName());
>              entity.setAttributes(new JpaAttributes());
>
>              if (!Util.isEmptyString(entityAnnotation.name()))
> {      // LINE 84
>                  entity.setName(entityAnnotation.name
> ());             // LINE 85
>              }
>
>              context.push(entity);
>          }
>
> OpenEJB TemporaryClassLoader has this code that I suspect may causes
> this error?? (I can't confirm it - it works in my OpenEJB integration
> test environment):
>
>          // Annotation classes must be loaded by the normal classloader
>          if (isAnnotationClass(bytes)) {
>              return Class.forName(name, resolve, getClass
> ().getClassLoader());
>          }
>
> While the bug may still be on Cayenne end, I wonder if Dain or
> somebody else from Geronimo can comment on this?
>
> Andrus
>


Re: Caynne with Geronimo NPE

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Feb 27, 2007, at 4:37 PM, Lasantha Ranaweera wrote:


> BTW as a solution I changed the given lines in EntityMapLoader  
> class, then
> it goes bit further and failed in Visitor classes again.
>
> ClassLoader loader = context.getTempClassLoader(); //caynne  
> existing one
> ClassLoader loader = persistenceUnit.getClassLoader(); //my  
> soultion since

We can't use the unit main ClassLoader at the point of loading the  
annotations, as annotations processing predates class enhancement,  
and we can't pollute the main class loader with unenhanced classes.


> Caused by: java.lang.NullPointerException
>         at
> org.apache.cayenne.jpa.conf.ClassAnnotationProcessorFactory 
> $EntityProcessor.onStartElement 
> (ClassAnnotationProcessorFactory.java:85)
>         at
> org.apache.cayenne.jpa.conf.EntityMapAnnotationLoader.loadClassMapping 
> (EntityMapAnnotationLoader.java:202)
>         at
> org.apache.cayenne.jpa.conf.EntityMapLoader.loadFromAnnotations 
> (EntityMapLoader.java:195)
>         at
> org.apache.cayenne.jpa.conf.EntityMapLoader.loadEntityMap 
> (EntityMapLoader.java:97)
>         ... 28 more


I assume there is a line mismatch, and the NPE is really at line 84,  
so "element.getAnnotation(Entity.class)" returns null:

        public void onStartElement(
                 AnnotatedElement element,
                 AnnotationProcessorStack context) {
             Entity entityAnnotation = element.getAnnotation 
(Entity.class);

             JpaEntity entity = new JpaEntity();
             entity.setClassName(((Class) element).getName());
             entity.setAttributes(new JpaAttributes());

             if (!Util.isEmptyString(entityAnnotation.name()))  
{      // LINE 84
                 entity.setName(entityAnnotation.name 
());             // LINE 85
             }

             context.push(entity);
         }

OpenEJB TemporaryClassLoader has this code that I suspect may causes  
this error?? (I can't confirm it - it works in my OpenEJB integration  
test environment):

         // Annotation classes must be loaded by the normal classloader
         if (isAnnotationClass(bytes)) {
             return Class.forName(name, resolve, getClass 
().getClassLoader());
         }

While the bug may still be on Cayenne end, I wonder if Dain or  
somebody else from Geronimo can comment on this?

Andrus