Possible Solutions

This topic applies to java version only

Of course, if you only use JDK5 or 6 there are no worries about the final fields at all. But if you do not want to stick to the definite java version and need to have the flexibility of switching to different java versions you currently have 2 solutions:

An example of the final fields translator can look like this:

FinalFieldTranslator.java
01package com.db4odoc.finalfields; 02import com.db4o.*; 03import com.db4o.config.*; 04 05// Translator allowing to store final fields on any Java version 06public class FinalFieldTranslator implements ObjectConstructor 07{ 08 09 public Object onStore(ObjectContainer container, Object applicationObject) { 10 System.out.println("onStore for "+applicationObject); 11 TestFinal notStorable=(TestFinal)applicationObject; 12 // final fields values are stored to an array of objects 13 return new Object[]{new Integer(notStorable._final_i), notStorable._final_s}; 14 } 15 16 public Object onInstantiate(ObjectContainer container, Object storedObject){ 17 System.out.println("onInstantiate for "+storedObject); 18 Object[] raw=(Object[])storedObject; 19 // final fields values are restored from the array of objects 20 int i=((Integer)raw[0]).intValue(); 21 String s = (String)raw[1]; 22 return new TestFinal(i,s); 23 } 24 25 public void onActivate(ObjectContainer container, Object applicationObject, Object storedObject) { 26 System.out.println("onActivate for "+applicationObject 27 +" / "+storedObject); 28 } 29 30 public Class storedClass() { 31 return Object[].class; 32 } 33}

The following call should be issued before opening the ObjectContainer to connect the translator to the TestFinal class:

Db4o.configure().objectClass(TestFinal.class).translate(new FinalFieldTranslator());