users@glassfish.java.net

Re: Java Persistence and ClassLoaders

From: <glassfish_at_javadesktop.org>
Date: Wed, 12 Dec 2007 10:46:04 PST

> Since you generate source code, why don't you do it
> during development
> as opposed to runtime? That will solve all your
> problems, only thing is
> the application would be non-portable as it would not
> contain classes
> which are specific to your provider.

I can certainly provide a build task that will do the code generation as part of the build, but in my experience adding an extra step like this generally deters too many people from trying out a solution.

> How does EMF know about these generated class to
> instantiate them?
> Reflection?

Yes, by reflection, but actually only one class is loaded this way - the rest are statically loaded by this first class.

> defineClass is a protected method. How did you call
> it? If you called it
> from your own subclass, then that's not going to make
> it available in
> the namespace of its delegate.

defineClass is called by reflection without subclassing anything.

> By writing some custom, GlassFish specific code, it
> is possible to
> extend GlassFish to integrate with your persistence
> provider such that
> the code generation happens only when an application
> is deployed. The
> generated classes can then be automatically made
> available to runtime
> class loader every time application is loaded in the
> system. Take a look
> at PersistenceProcessor.java [1] to see how we use a
> similar trick to
> generate DDLs (a.k.a. Java2DB) using TopLink.

I'll take a look at this, thanks
[Message sent by forum member 'dawidcha' (dawidcha)]

http://forums.java.net/jive/thread.jspa?messageID=249774