openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hugh (JIRA)" <>
Subject [jira] Commented: (OPENJPA-1860) How do I get OpenJPA to use my custom classloader to load Entity classes?
Date Mon, 08 Nov 2010 00:06:06 GMT


Hugh commented on OPENJPA-1860:

After a lot of permutations I've concluded that this works, but only in limited conditions:
1. Compiling with the PCEnhancerTask requires loading the openjpa.ClassResolver which requires
access to any configuration resources needed to modify orm.xml. To work around this I put
a dummy persistence-unit as the first persistence-unit in persistence.xml because it only
attempts to do this for the first PU. This seems to be rather arbitrary but I suppose it help
when you want to modify the classes at compile time.
2. The only ClassLoader method called which can be overridden to modify META-INF/orm.xml is
public Enumeration<URL> getResources(String name) throws IOException;
None of the others are called when accessing orm.xml. This means that I need to write an actual
file with the modifications I require at runtime and return the URL for that file from that
3. NamedQueries can't be used because for some reason they use the jar's META-INF/orm.xml
without the openjpa.ClassResolver and the class annotations with openjpa.ClassResolver.
This works, but it's clumsy and awkward.

My question is, why isn't getResource and getResourceAsStream called by OpenJPA on the openjpa.ClassResolver
to retrieve META-INF/orm.xml?

> How do I get OpenJPA to use my custom classloader to load Entity classes?
> -------------------------------------------------------------------------
>                 Key: OPENJPA-1860
>                 URL:
>             Project: OpenJPA
>          Issue Type: Question
>          Components: jpa
>    Affects Versions: 2.0.1
>         Environment: OpenJPA 2.0.1 Java 1.6-22
>            Reporter: Hugh
>         Attachments: ORM.xml, persistence.xml,
> I have written a custom classloader and I can't work out how to get OpenJPA to use it
to load my entity classes.
> I've followed instructions I found to set Thread.currentThread().setContextClassLoader()
at startup before loading any EntityManager and it seems to load the OpenJPA classes and a
lot of others, but not the class I'm interested in.
> Is this the right approach?
> If so, where have I gone wrong? (
> If not, how should this be done?
> Is there some sort of guide to accomplishing this that someone could point me to?
> Thanks.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message