You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Corey Klaasmeyer <co...@valentechnologies.com> on 2008/01/22 15:27:19 UTC

Runtime ByteCode Generation ClassNotFoundException in OpenJPA 1.0.1

I'm generating persistent classes at runtime which are transformed by
the PCClassFileTransformer.transform(ClassLoader, String, Class,
ProtectionDomain, byte[]) method. Unfortunately, the result of the
BCClass.getType() passed as the first argument to the method
MetaDataRepository.getMetaData(Class, ClassLoader, boolean) in
PCEnhancer(OpenJPAConfiguration, BCClass, MetaDataRepository,
ClassLoader) throws a ClassNotFoundException -- the transformer is
attempting to load a class that is not defined, therefore not loadable,
until transformation is complete. Is there some fundamental reason why
the enhancer needs a reference to a defined class rather than just the
bytecode?

It seems like it might be possible to cache enhanced bytecode by class
name until after transformation and all classes are defined.

Corey


Re: Runtime ByteCode Generation ClassNotFoundException in OpenJPA 1.0.1

Posted by Craig L Russell <Cr...@Sun.COM>.
Hi Corey,

The class must be loadable in order for OpenJPA to introspect it. So  
the classloader in which the class is created must first create it and  
then let OpenJPA enhance it.

In the application server interfaces there is a specific mechanism to  
allow the class to be loaded by a temporary class loader. If you look  
around in this code, you might find a way to define your dynamic class  
using a special class loader and then ask OpenJPA to use this class  
loader as input to enhance the class.

Applying this to the built-in transformer implementation might also be  
possible by changing the transform method. If you detect that the  
class does not exist, you could use a dynamically created class loader  
to create the class from the byte array and then use that class  
definition in the OpenJPA transform method.

Craig

On Jan 23, 2008, at 12:17 AM, Patrick Linskey wrote:

> Hi,
>
>> It seems like it might be possible to cache enhanced bytecode by  
>> class
>> name until after transformation and all classes are defined.
>
> It certainly should be possible, but currently, OpenJPA uses
> reflection to load a bunch of information about the class during
> enhancement.
>
> -Patrick
>
> On Jan 22, 2008 6:27 AM, Corey Klaasmeyer
> <co...@valentechnologies.com> wrote:
>> I'm generating persistent classes at runtime which are transformed by
>> the PCClassFileTransformer.transform(ClassLoader, String, Class,
>> ProtectionDomain, byte[]) method. Unfortunately, the result of the
>> BCClass.getType() passed as the first argument to the method
>> MetaDataRepository.getMetaData(Class, ClassLoader, boolean) in
>> PCEnhancer(OpenJPAConfiguration, BCClass, MetaDataRepository,
>> ClassLoader) throws a ClassNotFoundException -- the transformer is
>> attempting to load a class that is not defined, therefore not  
>> loadable,
>> until transformation is complete. Is there some fundamental reason  
>> why
>> the enhancer needs a reference to a defined class rather than just  
>> the
>> bytecode?
>>
>> It seems like it might be possible to cache enhanced bytecode by  
>> class
>> name until after transformation and all classes are defined.
>>
>> Corey
>>
>>
>
>
>
> -- 
> Patrick Linskey
> 202 669 5907

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Re: Runtime ByteCode Generation ClassNotFoundException in OpenJPA 1.0.1

Posted by Patrick Linskey <pl...@gmail.com>.
Hi,

> It seems like it might be possible to cache enhanced bytecode by class
> name until after transformation and all classes are defined.

It certainly should be possible, but currently, OpenJPA uses
reflection to load a bunch of information about the class during
enhancement.

-Patrick

On Jan 22, 2008 6:27 AM, Corey Klaasmeyer
<co...@valentechnologies.com> wrote:
> I'm generating persistent classes at runtime which are transformed by
> the PCClassFileTransformer.transform(ClassLoader, String, Class,
> ProtectionDomain, byte[]) method. Unfortunately, the result of the
> BCClass.getType() passed as the first argument to the method
> MetaDataRepository.getMetaData(Class, ClassLoader, boolean) in
> PCEnhancer(OpenJPAConfiguration, BCClass, MetaDataRepository,
> ClassLoader) throws a ClassNotFoundException -- the transformer is
> attempting to load a class that is not defined, therefore not loadable,
> until transformation is complete. Is there some fundamental reason why
> the enhancer needs a reference to a defined class rather than just the
> bytecode?
>
> It seems like it might be possible to cache enhanced bytecode by class
> name until after transformation and all classes are defined.
>
> Corey
>
>



-- 
Patrick Linskey
202 669 5907