openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "catalina wei" <catalina....@gmail.com>
Subject Re: Using custom ValueHandler
Date Fri, 11 Apr 2008 23:30:40 GMT
Mikolaj,
My suggestion is  try placing your valueHandler under
org.apche.openjpa.jdbc.meta.strats package, see if that would get your
valueHandler class loaded OK.
If that works, then open a jira issue for the problem, we need to fix
CFMetaDataParser.classForName() to use application class loader to load
user's valueHandler.

Here is a possible fix to CFMetaDataParser.java:
    protected Class classForName(String name, boolean resolve)
        throws SAXException {
        if (name == null)
            return null;
        Class cls = classForName(name, _package, resolve,
currentClassLoader());
        if (cls == null) {
            // 2nd attempt, use application class loader to load
            classForName(name, _package, resolve,
                (ClassLoader) AccessController.doPrivileged(
                    J2DoPrivHelper.getContextClassLoaderAction()));
            if (cls == null)
                throw getException(_loc.get("invalid-class",
name).getMessage());
        }
        return cls;
    }

Catalina

On 4/11/08, MikoĊ‚aj Gierulski <mikolaj.gierulski@javatech.com.pl> wrote:
>
> Hello,
> I am trying to use a custom ValueHandler to map custom objects to columns.
> I have implemented a class
> pl.com.agora.testcase.valuehandler.ConfigurationOptionValueHandler
> extends org.apache.openjpa.jdbc.meta.strats.AbstractValueHandler
>
> In my entities I use it as follows:
>     @Persistent
>     @Column(name = "OPTION")
>
>     @Strategy("pl.com.agora.testcase.valuehandler.ConfigurationOptionValueHandler")
>     private ConfigurationOption option;
>
> The problem is, an org.apache.openjpa.persistence.ArgumentException is
> thrown on the first attempt to access the entity, where the root of
> the problem is:
>
> org.apache.openjpa.persistence.ArgumentException:
> "pl.com.agora.testcase.entity.TestEntity.option" declared custom value
> handler
> "pl.com.agora.testcase.valuehandler.ConfigurationOptionValueHandler",
> but this handler cannot be instantiated.
>         at
> org.apache.openjpa.jdbc.meta.MappingRepository.namedHandler(MappingRepository.java:949)
>         at
> org.apache.openjpa.jdbc.meta.MappingRepository.defaultStrategy(MappingRepository.java:712)
>         at
> org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(RuntimeStrategyInstaller.java:62)
>         at
> org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.java:438)
>         at
> org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:403)
>         at
> org.apache.openjpa.jdbc.meta.ClassMapping.resolveNonRelationMappings(ClassMapping.java:823)
>         at
> org.apache.openjpa.jdbc.meta.MappingRepository.prepareMapping(MappingRepository.java:319)
>         at
> org.apache.openjpa.meta.MetaDataRepository.preMapping(MetaDataRepository.java:605)
>         at
> org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:492)
>         ... 83 more
> Caused by: <1.0.0 fatal user error>
> org.apache.openjpa.persistence.ArgumentException: The class name
> "pl.com.agora.testcase.valuehandler.ConfigurationOptionValueHandler"
> used in a metadata extension on field
> "pl.com.agora.testcase.entity.TestEntity.option" is not valid.
>         at
> org.apache.openjpa.meta.JavaTypes.classForName(JavaTypes.java:227)
>         at
> org.apache.openjpa.meta.JavaTypes.classForName(JavaTypes.java:194)
>         at
> org.apache.openjpa.jdbc.meta.MappingRepository.namedHandler(MappingRepository.java:939)
>         ... 91 more
>
> I did some debugging and found out, that the problem seems to be, that
> the method
> org.apache.openjpa.lib.meta.CFMetaDataParser.classForName(String name,
> String pkg, boolean resolve, ClassLoader loader)
> called by
> org.apache.openjpa.meta.JavaTypes.classForName(String name,
> ClassMetaData meta, Class dec, ValueMetaData vmd, ClassLoader loader)
>
> returns null instead of my ConfigurationOptionValueHandler class.
>
> If I call this method from within my application though, with
> classloader set to null and other arguments the same, it works
> properly and returns desired class.
>
> I am using bea weblogic 10.0.1 with openjpa 1.0.0
> The ConfigurationOptionValueHandler class is located in the same jar
> file, as the TestEntity class.
> This jar file is located in a lib folder of a war installed as a
> library on the server.
> My application is also installed as a war and depends on that library.
>
> My guess is the value handler should be located somewhere else, but I
> don't know where this should be.
>
> Any suggestions will be much appreciated.
>
> Best regards,
> Mikolaj.
>
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message