4 Replies Latest reply: May 30, 2008 5:04 PM by greybird RSS

    IllegalArgumentException trying to evolve a class with collection field

      Dear JE Community,

      I hope there is an expert in the class evolution among you who can help me with this:

      I tried to evolve a class with a persistent collection field using Converter(String className, int classVersion, Conversion conversion) mutation. The collection I used was an instance of java.util.TreeSet. I did not define my own proxy to store collection data.

      No changes to the collection data were being made during the conversion - I just wanted to copy these properties to my evolved objects. The code I used to copy raw data looked like this:

      public Object convert(Object fromValue)
      RawObject old = (RawObject)fromValue;
      Map<String, Object> values = old.getValues();
      Map<String, Object> newValues = new HashMap<String, Object>();
      newValues.put("keywords", values.remove("keywords"));
      return new RawObject(newType, newValues, null);

      Attempt to open a converted object ended with exception:

      Exception in thread "main" java.lang.IllegalArgumentException: Raw value class:
      java.util.TreeSet must be RawObject a simple type
      at com.sleepycat.persist.impl.RawAbstractInput.checkAndConvert(RawAbstractInput.java:104)
      at com.sleepycat.persist.impl.RawComplexInput.readNext(RawComplexInput.java:44)
      at com.sleepycat.persist.impl.RawAbstractInput.readObject(RawAbstractInput.java:38)
      at com.sleepycat.persist.impl.ReflectionAccessor$ObjectAccess.read(ReflectionAccessor.java:375)
      at com.sleepycat.persist.impl.ReflectionAccessor.readNonKeyFields(Reflec
      at com.sleepycat.persist.impl.ComplexFormat.readObject(ComplexFormat.java:472)
      at com.sleepycat.persist.impl.ComplexFormat.convertRawObject(ComplexFormat.java:614)
      at com.sleepycat.persist.impl.PersistCatalog.convertRawObject(PersistCatalog.java:922)
      at com.sleepycat.persist.impl.ConverterReader.readObject(ConverterReader.java:55)
      at com.sleepycat.persist.impl.PersistEntityBinding.readEntity(PersistEntityBinding.java:89)
      at com.sleepycat.persist.impl.PersistEntityBinding.entryToObject(PersistEntityBinding.java:59)
      at com.sleepycat.persist.EntityValueAdapter.entryToValue(EntityValueAdapter.java:56)
      at com.sleepycat.persist.BasicCursor.returnValue(BasicCursor.java:206)
      at com.sleepycat.persist.BasicCursor.next(BasicCursor.java:74)
      at com.sleepycat.persist.BasicCursor.next(BasicCursor.java:68)
      at Test.main(Test.java:47)

      I am using Berkeley DB Java Edition version 3.2.68 with Sun JDK 1.5 SE on Windows XP. I have a simplified code sample that can be used to reproduce this (5 files in archive).

      Have I done something wrong? Does JE support Conversion mutation for classes with collection fields? Is this a bug in JE?

      Thank you,
        • 1. Re: IllegalArgumentException trying to evolve a class with collection field
          Hi Stan,

          I can help you with this. Could you please send me the archive with the complete test so I can take a closer look? My email is mark.hayes at the obvious domain (oracle.com).

          • 2. Re: IllegalArgumentException trying to evolve a class with collection field

            Thanks for sending a complete test -- I appreciate it!

            I'm not sure why your Conversion isn't working, I'm still looking into that. So far, it looks like you've implemented it correctly. I'll let you know what I find as I dig deeper.

            However, as a separate issue, I'm wondering why you need a Conversion mutation. It looks like in version 1 of your class you've added a String field -- description -- and you want to give it a default value. You can do that without any mutations. You can assign the default value when the description field is declared or in the default constructor. Either way, if there is a stored description (for a stored version 1 of your class), the stored value will overwrite the default value.

            Will that work for you? Or do you need the Conversion mutation for other reasons?

            • 3. Re: IllegalArgumentException trying to evolve a class with collection field

              Thanks for looking into my issue. I tried to use Conversion mutation in my application to change hierarchy of a persistent class. When I discovered that collection data cannot be copied during the evolution, I built this test to isolate the problem. I cut off extra stuff from the test to see exactly what the problem was.

              Since I am working with a live database I have to be very careful when I refactor persistent classes. I am trying to avoid store conversion if possible. Thus far, I found a workaround that allowed me to keep my existing class hierarchy. I hope I will be able to overcome this limitation on collection conversions in future and appreciate your help.
              • 4. Re: IllegalArgumentException trying to evolve a class with collection field
                Thanks Stan, I understand. I will look into the problem and get back to you in the next few days -- within a week. In the meantime, I'm glad that you have a workaround.