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 Mon, 14 Apr 2008 15:27:18 GMT
Hi Mikołaj,
Do you know how to build openjpa jar with my proposed fix ? Could you test
that with your original package "pl.com.agora.testcase.valuehandler" ?
This is a problem often seen in JEE environment, the classloader (1)  loaded
openjpa jars is not the same as
the classloader (2) loaded your application jar. The method
currentClassLoader() returns classloader (1) if the loader is present --
see  XMLMetaDataParser.currentClassLoader().

If my proposed fix works for you, I can open jira issue and checkin the fix.
Thank you.

Catalina

On 4/14/08, Mikołaj Gierulski <mikolaj.gierulski@javatech.com.pl> wrote:
>
> Catalina,
> thank you kindly for your quick response.
>
> When I put the class in the ''org.apache.openjpa.jdbc.meta.strats"
> and then put it in the openjpa jar file, it works. If I leave it in my
> application jar file, the class still doesn't load.
> If I put the class with my package
> "pl.com.agora.testcase.valuehandler" in the openjpa jar file it works.
> Actually, when I put my value handler class in a jar and place it on
> weblogic classpath (for example add the path to the file to
> PRE_CLASSPATH variable in weblogic setEnv.cmd) it works fine.
> So it seems the classloader used in the method described by you can't
> load the application classes.
>
> By the way, how do I open jira issue?
>
> Best regards,
> Mikolaj
>
> 2008/4/12 catalina wei <catalina.wei@gmail.com>:
>
> > 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