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

Reply via email to