[
https://issues.apache.org/jira/browse/OPENJPA-367?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12526887
]
Albert Lee commented on OPENJPA-367:
------------------------------------
Patrick, thanks for the pointer to the serp code. It helps a lot. This problem
has nothing to do with Serp.
The scope of the problem is:
1) When pcEnhancer is invoked with a target (i.e.
test.XMLDatatypeSupportTestEntity), the ClassArgParser.parseTypes() is called
to process the arguments and indirectly the entity is loaded using the
TemporaryClassLoader. Subsequently, when the orm.xml is parsed, the same
TemporaryClassLoader is used as the key to the meta data repository map.
TemporaryClassLoader.loadClass(String, boolean) line: 78
TemporaryClassLoader.loadClass(String) line: 44
ClassLoader.defineClassImpl(String, byte[], int, int, Object) line: not
available [native method]
TemporaryClassLoader(ClassLoader).defineClass(String, byte[], int, int,
ProtectionDomain) line: 224
TemporaryClassLoader(ClassLoader).defineClass(String, byte[], int, int)
line: 163
TemporaryClassLoader.loadClass(String, boolean) line: 78
TemporaryClassLoader.loadClass(String) line: 44
Class<T>.forNameImpl(String, boolean, ClassLoader) line: not available
[native method]
Class<T>.forName(String, boolean, ClassLoader) line: 164
Strings.toClass(String, boolean, ClassLoader) line: 162
Strings.toClass(String, ClassLoader) line: 108
ClassArgParser.parseTypes(String) line: 164
PCEnhancer.run(OpenJPAConfiguration, String[], PCEnhancer$Flags,
MetaDataRepository, BytecodeWriter, ClassLoader) line: 4333
PCEnhancer.run(OpenJPAConfiguration, String[], Options) line: 4296
PCEnhancer.main(String[]) line: 4268
2) When no target is specified, the argument process is skipped and proceed to
meta-data processing. The first step to do is to load entity class using
serp.Project. Currently, the project's loadClass() method is called without a
classloader, therefore Project uses a default, which is the application context
classloader (Thread.currentThread().getContextClassLoader();)
However, the remaining meta-data processing follow the exactly the same path as
the successfully scenario and use the TemporaryClassLoader to load the entity
class. This later entity Class object is used as the key to the meta-data
repository map. When all the processing is finished,
MetaDataRepository.getMetaDataInternal( entityClass_from_applCtxtClassLoader)
is called to lookup the meta data and was not found.
--------------------------------
PCEnhancer.java
for (Iterator itr = classes.iterator(); itr.hasNext();) {
Object o = itr.next();
if (log.isTraceEnabled())
log.trace(_loc.get("enhance-running", o));
if (o instanceof String)
bc = project.loadClass((String) o, loader); //<<<< loader is
added to resolve the observed problem
else
bc = project.loadClass((Class) o);
enhancer = new PCEnhancer(conf, bc, repos, loader);
--------------------------------
serp.Project.java
public BCClass loadClass(String name) {
return loadClass(name, null);
}
--------------------------------
public BCClass loadClass(String name, ClassLoader loader) {
// convert to proper Class.forName() form
name = _names.getExternalForm(name, false);
BCClass cached = checkCache(name);
if (cached != null)
return cached;
// check for existing type
if (loader == null)
loader = Thread.currentThread().getContextClassLoader();
try {
return loadClass(Strings.toClass(name, loader));
} catch (Exception e) {
}
--------------------------------
I modified PCEnhancer.run method and add the classloader parameter to the
project.loadClass() call to request Project to load the entity class using the
TemporaryClassLoader. This seems to fix the problem.
if (o instanceof String)
bc = project.loadClass((String) o, loader); //<<<< loader is
added to resolve the observed problem
Is this the correct fix strategy for this problem?
Thanks,
Albert Lee
> PCEnhancer does not find meta data for entities using pure XML annotation
> -------------------------------------------------------------------------
>
> Key: OPENJPA-367
> URL: https://issues.apache.org/jira/browse/OPENJPA-367
> Project: OpenJPA
> Issue Type: Bug
> Components: kernel
> Affects Versions: 1.0.0
> Environment: All platforms
> Reporter: Albert Lee
> Attachments: OPENJPA-367.test.jar
>
>
> When an entity is defined using pure XML (i.e. no annotation in the entity
> class), the enhancer does not recognized the meta data and no enhancing will
> take place: E.g.
> -----------------------------------------
> C:\temp\test>runPcEnhancer.bat
> C:\temp\test>java -cp
> C:\temp\test\;C:\temp\test\openjpa-1.1.0-SNAPSHOT.jar;C:\temp\test\utils.jar;C:\temp\test\geronimo-jpa_3.0_spec-1.0.jar;C:\temp\test\geronimo-jta_1.1_spec-1.1.jar
> org.apache.openjpa.enhance.PCEnhancer
> 15 EntityUnit_JSE TRACE [main] openjpa.Runtime - Setting the following
> properties from "file:/C:/temp/test/META-INF/persistence.xml" into
> configuration: {openjpa.Id=EntityUnit_JSE, openjpa.Log=DefaultLevel=TRACE,
> openjpa.MetaDataFactory=jpa(Resources=META-INF/jpamappings.xml,
> Types=test.XMLDatatypeSupportTestEntity)}
> 31 EntityUnit_JSE TRACE [main] openjpa.Runtime - No cache marshaller found
> for id org.apache.openjpa.conf.MetaDataCacheMaintenance.
> 47 EntityUnit_JSE INFO [main] openjpa.Tool - No targets were given.
> Running on all classes in your persistent classes list, or all metadata files
> in classpath directories if you have not listed your persistent classes. Use
> -help to display tool usage information.
> 62 EntityUnit_JSE TRACE [main] openjpa.MetaData - Scanning resource
> "META-INF/jpamappings.xml" for persistent types.
> 62 EntityUnit_JSE TRACE [main] openjpa.MetaData - Scan of
> "META-INF/jpamappings.xml" found persistent types
> [Ljava.lang.String;@3a183a18.
> 62 EntityUnit_JSE TRACE [main] openjpa.MetaData - Mapping resource
> location "file:/C:/temp/test/META-INF/jpamappings.xml" to persistent types
> "[test.XMLDatatypeSupportTestEntity]".
> 62 EntityUnit_JSE TRACE [main] openjpa.MetaData - Scanning resource
> "META-INF/orm.xml" for persistent types.
> 62 EntityUnit_JSE TRACE [main] openjpa.MetaData -
> parsePersistentTypeNames() found [test.XMLDatatypeSupportTestEntity].
> 62 EntityUnit_JSE TRACE [main] openjpa.MetaData - Found 1 classes with
> metadata in 15 milliseconds.
> 62 EntityUnit_JSE TRACE [main] openjpa.Tool - Enhancer running on type
> "test.XMLDatatypeSupportTestEntity".
> 93 EntityUnit_JSE TRACE [main] openjpa.MetaData - Loading metadata for
> "class test.XMLDatatypeSupportTestEntity" under mode "[META]".
> 125 EntityUnit_JSE TRACE [main] openjpa.MetaData - Parsing resource
> "file:/C:/temp/test/META-INF/jpamappings.xml".
> 156 EntityUnit_JSE TRACE [main] openjpa.MetaData - Parsing class
> "test.XMLDatatypeSupportTestEntity".
> 172 EntityUnit_JSE TRACE [main] openjpa.MetaData - Generating default
> metadata for type "test.XMLDatatypeSupportTestEntity".
> 172 EntityUnit_JSE TRACE [main] openjpa.MetaData - Using reflection for
> metadata generation.
> 187 EntityUnit_JSE TRACE [main] openjpa.MetaData - Parsing class
> "test.XMLDatatypeSupportTestEntity".
> 187 EntityUnit_JSE TRACE [main] openjpa.MetaData - Parsing package
> "test.XMLDatatypeSupportTestEntity".
> 187 EntityUnit_JSE TRACE [main] openjpa.MetaData - Finished parsing
> metadata resource "file:/C:/temp/test/META-INF/jpamappings.xml".
> 187 EntityUnit_JSE TRACE [main] openjpa.MetaData - Parsing class
> "test.XMLDatatypeSupportTestEntity".
> 187 EntityUnit_JSE TRACE [main] openjpa.Enhance - Enhancing type "class
> test.XMLDatatypeSupportTestEntity".
> 203 EntityUnit_JSE WARN [main] openjpa.Enhance - Type "class
> test.XMLDatatypeSupportTestEntity" has no metadata; enhancing as persistence
> aware. If you intended for "class test.XMLDatatypeSupportTestEntity" to be
> persistence-capable, then this means that OpenJPA could not find any metadata
> for "class test.XMLDatatypeSupportTestEntity". This can happen if the
> directory containing your metadata is not in your CLASSPATH, or if your
> metadata files are not named properly. See the documentation on metadata
> placement for more information.
> 203 EntityUnit_JSE TRACE [main] openjpa.Tool - The class does not have
> metadata - enhanced as persistence-aware.
> -----------------------------------------
> However if the target is specified, the enhancement will occur, E.g.
> -----------------------------------------
> C:\temp\test>runPcEnhancer.bat test.XMLDatatypeSupportTestEntity
> C:\temp\test>java -cp
> C:\temp\test\;C:\temp\test\openjpa-1.1.0-SNAPSHOT.jar;C:\temp\test\utils.jar;C:\temp\test\geronimo-jpa_3.0_spec-1.0.jar;C:\temp\test\geronimo-jta_1.1_spec-1.1.jar
> org.apache.openjpa.enhance.PCEnhancer test.XMLDatatypeSupportTestEntity
> 15 EntityUnit_JSE TRACE [main] openjpa.Runtime - Setting the following
> properties from "file:/C:/temp/test/META-INF/persistence.xml" into
> configuration: {openjpa.Id=EntityUnit_JSE, openjpa.Log=DefaultLevel=TRACE,
> openjpa.MetaDataFactory=jpa(Resources=META-INF/jpamappings.xml,
> Types=test.XMLDatatypeSupportTestEntity)}
> 47 EntityUnit_JSE TRACE [main] openjpa.Runtime - No cache marshaller found
> for id org.apache.openjpa.conf.MetaDataCacheMaintenance.
> 78 EntityUnit_JSE TRACE [main] openjpa.Runtime - No cache marshaller found
> for id org.apache.openjpa.conf.MetaDataCacheMaintenance.
> 94 EntityUnit_JSE TRACE [main] openjpa.Tool - Enhancer running on type
> "class test.XMLDatatypeSupportTestEntity".
> 125 EntityUnit_JSE TRACE [main] openjpa.MetaData - Loading metadata for
> "class test.XMLDatatypeSupportTestEntity" under mode "[META]".
> 125 EntityUnit_JSE TRACE [main] openjpa.MetaData - Scanning resource
> "META-INF/jpamappings.xml" for persistent types.
> 125 EntityUnit_JSE TRACE [main] openjpa.MetaData - Scan of
> "META-INF/jpamappings.xml" found persistent types
> [Ljava.lang.String;@20962096.
> 140 EntityUnit_JSE TRACE [main] openjpa.MetaData - Mapping resource
> location "file:/C:/temp/test/META-INF/jpamappings.xml" to persistent types
> "[test.XMLDatatypeSupportTestEntity]".
> 140 EntityUnit_JSE TRACE [main] openjpa.MetaData - Scanning resource
> "META-INF/orm.xml" for persistent types.
> 140 EntityUnit_JSE TRACE [main] openjpa.MetaData -
> parsePersistentTypeNames() found [test.XMLDatatypeSupportTestEntity].
> 140 EntityUnit_JSE TRACE [main] openjpa.MetaData - Found 1 classes with
> metadata in 15 milliseconds.
> 156 EntityUnit_JSE TRACE [main] openjpa.MetaData - Parsing resource
> "file:/C:/temp/test/META-INF/jpamappings.xml".
> 187 EntityUnit_JSE TRACE [main] openjpa.MetaData - Parsing class
> "test.XMLDatatypeSupportTestEntity".
> 187 EntityUnit_JSE TRACE [main] openjpa.MetaData - Generating default
> metadata for type "test.XMLDatatypeSupportTestEntity".
> 187 EntityUnit_JSE TRACE [main] openjpa.MetaData - Using reflection for
> metadata generation.
> 203 EntityUnit_JSE TRACE [main] openjpa.MetaData - Parsing class
> "test.XMLDatatypeSupportTestEntity".
> 219 EntityUnit_JSE TRACE [main] openjpa.MetaData - Finished parsing
> metadata resource "file:/C:/temp/test/META-INF/jpamappings.xml".
> 219 EntityUnit_JSE TRACE [main] openjpa.MetaData - Set persistence-capable
> superclass of "test.XMLDatatypeSupportTestEntity" to "null".
> 219 EntityUnit_JSE TRACE [main] openjpa.MetaData - Resolving metadata for
> "[EMAIL PROTECTED]".
> 219 EntityUnit_JSE TRACE [main] openjpa.MetaData - Resolving field
> "[EMAIL PROTECTED]".
> 219 EntityUnit_JSE TRACE [main] openjpa.MetaData - Resolving field
> "[EMAIL PROTECTED]".
> 250 EntityUnit_JSE TRACE [main] openjpa.MetaData - Preparing mapping for
> "test.XMLDatatypeSupportTestEntity".
> 250 EntityUnit_JSE TRACE [main] openjpa.MetaData - Resolving mapping for
> "[EMAIL PROTECTED]".
> 250 EntityUnit_JSE TRACE [main] openjpa.Enhance - Enhancing type "class
> test.XMLDatatypeSupportTestEntity".
> 312 EntityUnit_JSE TRACE [main] openjpa.MetaData - Clearing metadata
> repository "[EMAIL PROTECTED]".
> -----------------------------------------
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.