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>();
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
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?
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?
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.