4 Replies Latest reply: Nov 3, 2010 10:06 AM by Greybird-Oracle RSS

    class converter problem

    795271
      Hi All,
      I am not clear about how to write a correct class converter. Here is my example:

      old:
      @Persistent(proxyFor=Base.class)
      public class BaseProxy implements PersistentProxy<Base> {
        private Map<String, List<String>> onemap;
        ...
        
        @Persistent(proxyFor=A.class)
        public static class Aproxy extends BaseProxy {
            private Aproxy() {
            }
        }
      }
      new:
      @Persistent(proxyFor=Base.class, version=1)
      public class BaseProxy implements PersistentProxy<Base> {
        private Map<Enum, List<String>> onemap;    // changed the map
        private Map<String, List<String>> anothermap;    // added a new field.
        ...
        
        @Persistent(proxyFor=A.class, version=1)
        public static class Aproxy extends BaseProxy {
            private Aproxy() {
            }
        }
      }
      My class converter:
      public class BaseProxyConverter implements Conversion {
         public Object convert(Object fromValue) {
         ...
         }
      
         @Override
          public boolean equals(Object o) {
              ...
          }
      
          public static class AproxyConverter extends BaseProxyConverter {     
              @Override
              public Object convert(Object fromValue) {
                 ...
              }
              
              @Override
              public boolean equals(Object o) {
                  ...
              }
          }
      }
      Registration code:
      ...
                  
      Mutations mutations = new Mutations();
      
      Converter baseConverter = new Converter(BaseProxy.class.getName(), 0, new BaseProxyConverter());
      Converter aConverter = new Converter(Aproxy.class.getName(), 0, new BaseProxyConverter.AproxyConverter());
      mutations.addConverter(baseConverter);
      mutations.addConverter(aConverter);
      
      storeConfig.setMutations(mutations);
      ...
      But I got errors like :
      com.sleepycat.je.EnvironmentFailureException: (JE 4.0.103) java.io.InvalidClassException:
      BaseProxyConverter$AproxyConverter; local class incompatible: stream classdesc serialVersionUID = -6680580065857162115, local class serialVersionUID = 1948673003026236849 UNEXPECTED_EXCEPTION: Unexpected internal Exception, may have side effects.

      Can anyone provide help for this problem?
      Thanks a lot.

      Edited by: 792268 on 2010-11-2 下午4:01

      Edited by: 792268 on 2010-11-2 下午4:03

      Edited by: 792268 on 2010-11-2 下午4:04
        • 1. Re: class converter problem
          Greybird-Oracle
          Hi,

          Could you please post the full stack trace. I think there is at least one nested exception in there also.

          Thanks,
          --mark                                                                                                                                                                                                                                                                       
          • 2. Re: class converter problem
            795271
            Thanks.

            The following is the error message:

            local class incompatible: stream classdesc serialVersionUID = -6680580065857162115, local class serialVersionUID = 1948673003026236849 UNEXPECTED_EXCEPTION: Unexpected internal Exception, may have side effects.
                 at com.sleepycat.je.EnvironmentFailureException.unexpectedException(EnvironmentFailureException.java:286)
                 at com.sleepycat.compat.DbCompat.unexpectedException(DbCompat.java:500)
                 at com.sleepycat.persist.impl.PersistCatalog.readData(PersistCatalog.java:1110)
                 at com.sleepycat.persist.impl.PersistCatalog.init(PersistCatalog.java:255)
                 at com.sleepycat.persist.impl.PersistCatalog.<init>(PersistCatalog.java:221)
                 at com.sleepycat.persist.impl.Store.<init>(Store.java:186)
                 at com.sleepycat.persist.EntityStore.<init>(EntityStore.java:185)
                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:597)
                 at com.google.inject.internal.ProviderMethod.get(ProviderMethod.java:101)
                 at com.google.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:48)
                 at com.google.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:45)
                 at com.google.inject.InjectorImpl.callInContext(InjectorImpl.java:811)
                 at com.google.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:42)
                 at com.google.inject.Scopes$1$1.get(Scopes.java:54)
                 at com.google.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:48)
                 at com.google.inject.InjectorImpl$4$1.call(InjectorImpl.java:758)
                 at com.google.inject.InjectorImpl.callInContext(InjectorImpl.java:811)
                 at com.google.inject.InjectorImpl$4.get(InjectorImpl.java:754)
                 at com.google.inject.spi.ProviderLookup$1.get(ProviderLookup.java:89)
                 at com.google.inject.spi.ProviderLookup$1.get(ProviderLookup.java:89)
                 at com.google.inject.internal.ProviderMethod.get(ProviderMethod.java:95)
                 at com.google.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:48)
                 at com.google.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:45)
                 at com.google.inject.InjectorImpl.callInContext(InjectorImpl.java:811)
                 at com.google.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:42)
                 at com.google.inject.Scopes$1$1.get(Scopes.java:54)
                 at com.google.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:48)
                 at com.google.inject.SingleParameterInjector.inject(SingleParameterInjector.java:42)
                 at com.google.inject.SingleParameterInjector.getAll(SingleParameterInjector.java:66)
                 at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:84)
                 at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
                 at com.google.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:45)
                 at com.google.inject.InjectorImpl.callInContext(InjectorImpl.java:811)
                 at com.google.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:42)
                 at com.google.inject.Scopes$1$1.get(Scopes.java:54)
                 at com.google.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:48)
                 at com.google.inject.FactoryProxy.get(FactoryProxy.java:56)
                 at com.google.inject.SingleParameterInjector.inject(SingleParameterInjector.java:42)
                 at com.google.inject.SingleParameterInjector.getAll(SingleParameterInjector.java:66)
                 at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:84)
                 at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
                 at com.google.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:45)
                 at com.google.inject.InjectorImpl.callInContext(InjectorImpl.java:811)
                 at com.google.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:42)
                 at com.google.inject.Scopes$1$1.get(Scopes.java:54)
                 at com.google.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:48)
                 at com.google.inject.FactoryProxy.get(FactoryProxy.java:56)
                 at com.google.inject.SingleParameterInjector.inject(SingleParameterInjector.java:42)
                 at com.google.inject.SingleParameterInjector.getAll(SingleParameterInjector.java:66)
                 at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:84)
                 at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
                 at com.google.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:45)
                 at com.google.inject.InjectorImpl.callInContext(InjectorImpl.java:811)
                 at com.google.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:42)
                 at com.google.inject.Scopes$1$1.get(Scopes.java:54)
                 at com.google.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:48)
                 at com.google.inject.SingleParameterInjector.inject(SingleParameterInjector.java:42)
                 at com.google.inject.SingleParameterInjector.getAll(SingleParameterInjector.java:66)
                 at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:84)
                 at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
                 at com.google.inject.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:45)
                 at com.google.inject.InjectorImpl.callInContext(InjectorImpl.java:811)
                 at com.google.inject.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:42)
                 at com.google.inject.Scopes$1$1.get(Scopes.java:54)
                 at com.google.inject.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:48)
                 at com.google.inject.SingleParameterInjector.inject(SingleParameterInjector.java:42)
                 at com.google.inject.SingleParameterInjector.getAll(SingleParameterInjector.java:66)
                 at com.google.inject.ConstructorInjector.construct(ConstructorInjector.java:84)
                 at com.google.inject.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:111)
                 at com.google.inject.InjectorImpl$4$1.call(InjectorImpl.java:758)
                 at com.google.inject.InjectorImpl.callInContext(InjectorImpl.java:804)
                 at com.google.inject.InjectorImpl$4.get(InjectorImpl.java:754)
                 at com.google.inject.InjectorImpl.getInstance(InjectorImpl.java:793)

                 at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:562)
                 at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1583)
                 at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
                 at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
                 at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
                 at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
                 at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
                 at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
                 at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
                 at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
                 at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
                 at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
                 at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
                 at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
                 at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
                 at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
                 at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
                 at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
                 at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
                 at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
                 at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
                 at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
                 at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
                 at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
                 at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
                 at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
                 at java.util.ArrayList.readObject(ArrayList.java:593)
                 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                 at java.lang.reflect.Method.invoke(Method.java:597)
                 at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
                 at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849)
                 at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
                 at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
                 at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
                 at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1871)
                 at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
                 at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
                 at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
                 at com.sleepycat.persist.impl.PersistCatalog.readData(PersistCatalog.java:1093)
                 ... 76 more

            Edited by: 792268 on 2010-11-2 下午5:44
            • 3. Re: class converter problem
              712739
              Hi,

              In order to help you debug the problem, we need to reproduce your error. So, I have several questions for you:
              1. What's your class hierarchy?
              I notice that, you have two proxy classes, BaseProxy and Aproxy, for two proxied classes, Base and A. Because I want to guarantee that your proxy classes are correctly defined, I want you to post out what's your proxy and proxied classes look like.
              You don't have to post out the original (or say the real) proxy and proxied classes. All I want know is the prototype of these classes. For example, below is my re-built of your proxy and proxied classes (of course they are not exactly like what in your sandbox), please modify them as close as to the classes in your sandbox.
              @Persistent(proxyFor=Base.class)
                  static class BaseProxy implements PersistentProxy<Base> {
                      private Map<String, List<String>> onemap;
                      
                      private BaseProxy() {}
                      
                      @Override
                      public Base convertProxy() {
                          return new Base(onemap);
                      }
                      
                      @Override
                      public void initializeProxy(Base object) {
                          onemap = object.getOnemap();
                      }
                    
                      @Persistent(proxyFor=A.class)
                      public static class Aproxy extends BaseProxy {
                          private Aproxy() {}
                          @Override
                          public Base convertProxy() {
                              //please fill it
                          }
                      
                          @Override
                          public void initializeProxy(Base object) {
                              //please fill it
                          }
                      }
                  }
                  
                  static class Base implements Serializable {
                      private static final long serialVersionUID = 1L;
                      private Map<String, List<String>> onemap;
                      
                      public Base( Map<String, List<String>> onemap) {
                          this.onemap = onemap;
                      }
                      
                      void setOnemap( Map<String, List<String>> onemap) {
                          this.onemap = onemap;
                      }
                      
                       Map<String, List<String>> getOnemap() {
                          return onemap;
                      }
                  }
                  
                  static class A implements Serializable {
                      private static final long serialVersionUID = 2L;
                      private int id;
                      
                      public A(int id) {
                          this.id = id;
                      }
                      
                      void setId(int id) {
                          this.id = id;
                      }
                      
                      int getId() {
                          return id;
                      }
                  }
              2. How do you serialize/deserialize the proxied class?
              Please note that, a proxy class just serves to serialize/deserialize the proxied class, rather then serialize/deserialize the proxy class themselves. For example, without proxy class BaseProxy, class Base cannot be stored by DPL. After define and register BaseProxy, now DPL can serialize/deserialize Base from now on. So I am a little confused why the fields in BaseProxy will be changed in new proxy class. Does it mean that the fields in Base class also be changed?

              Thanks advance for your further information.

              Eric,
              Berkeley DB, Java Edition
              Oracle
              • 4. Re: class converter problem
                Greybird-Oracle
                To add to what Eric said: We have not seen a problem like you've reported before. So we will need to reproduce it with a small test. Eric is trying to do that. If you have a small test you can send us, that will speed up the process.

                Thanks,
                --mark