This topic applies to java version only
Db4o uses reflection to store and retrieve objects from the database file. In the case of final fields db4o needs a successful call to java.lang.Field#setAccessible to allow write access to those fields. Unfortunately different Java versions produce different results in this case. To be more specific:
You can use the following example code to check final fields behavior with different java versions:
01/* Copyright (C) 2007 db4objects Inc. http://www.db4o.com */ 02
package com.db4odoc.finalfields; 03
import java.io.File; 04
05
import com.db4o.Db4o; 06
import com.db4o.ObjectContainer; 07
import com.db4o.ObjectSet; 08
09
public class TestFinal 10
{ 11
private static final String DB4O_FILE_NAME = "reference.db4o"; 12
// non-final fields 13
public int _i; 14
public String _s; 15
// final fields storing the same values as above 16
public final int _final_i; 17
public final String _final_s; 18
19
public static void main(String[] args) 20
{ 21
new File(DB4O_FILE_NAME).delete(); 22
ObjectContainer container = Db4o.openFile(DB4O_FILE_NAME); 23
try { 24
TestFinal test = new TestFinal(1,"test"); 25
container.set(test); 26
System.out.println("Added: " + test); 27
} finally { 28
// Close does implicit commit and refreshes the reference cache 29
container.close(); 30
} 31
container = Db4o.openFile(DB4O_FILE_NAME); 32
try { 33
ObjectSet result = container.get(null); 34
listResult(result); 35
} finally { 36
container.close(); 37
} 38
} 39
// end main 40
41
public TestFinal(int i, String s) 42
{ 43
// initialize final and non-final fields with the same values 44
_i = i; 45
_s = s; 46
_final_i = i; 47
_final_s = s; 48
} 49
// end TestFinal 50
51
public String toString() 52
{ 53
return "Int - " + _i + "; String - " + _s + "; FINAL Int - " + _final_i + "; FINAL String - " + _final_s; 54
} 55
// end toString 56
57
private static void listResult(ObjectSet result) 58
{ 59
while(result.hasNext()) { 60
System.out.println(result.next()); 61
} 62
} 63
// end listResult 64
}
If you are using Eclipse it is easy to switch between java versions - you can switch to the versions lower than the one installed on your computer without having to install them all. For example if you are using JDK6 you can easily test your project on JDK1.1 - 1.4 and JDK5. Just go to the project properties, select "Java Build Path" on the left panel and "Libraries" tab on the right panel. Remove the system library currently used. Select "Add library->JRE System Library"; on the next screen check the "Execution Environment" radio button and select the desired environment from the list.
Don't forget to use the appropriate db4o version for the selected java environment version. See db4o on Java Platforms for more information.