I have been storing an object which contains a GregorianCalendar object in a db4o database, which works just fine. However, on retrieving the object (after closing and re-opening the database), I cannot seem to access some of the information inside (namely get(GregorianCalendar.MONTH) ). I have included test code below, and am wondering how to fix this problem.
import static org.junit.Assert.assertEquals;
import java.util.GregorianCalendar;
import org.junit.Test;
import com.db4o.Db4oEmbedded;
import com.db4o.ObjectContainer;
import com.db4o.config.EmbeddedConfiguration;
public class DateTest {
public class RecordDate {
private GregorianCalendar calendar;
public RecordDate() {
calendar = new GregorianCalendar();
}
public int getMonth() {
return calendar.get(GregorianCalendar.MONTH);
}
}
@Test
public void testGetMonth() {
EmbeddedConfiguration config = Db4oEmbedded.newConfiguration();
config.common().objectClass(RecordDate.class).cascadeOnActivate(true);
config.common().objectClass(RecordDate.class).cascadeOnUpdate(true);
config.common().activationDepth(25);
config.common().updateDepth(25);
ObjectContainer database = Db4oEmbedded.openFile(config,
"db/datetest.db");
GregorianCalendar currentdate = new GregorianCalendar();
RecordDate testdate = new RecordDate();
assertEquals(currentdate.get(GregorianCalendar.MONTH),
testdate.getMonth()); // this passes
database.store(testdate);
database.close();
EmbeddedConfiguration config2 = Db4oEmbedded.newConfiguration();
config2.common().objectClass(RecordDate.class).cascadeOnActivate(true);
config2.common().objectClass(RecordDate.class).cascadeOnUpdate(true);
config2.common().activationDepth(25);
config2.common().updateDepth(25);
database = Db4oEmbedded.openFile(config2, "db/datetest.db");
testdate = (RecordDate) database.queryByExample(RecordDate.class)
.next();
assertEquals(currentdate.get(GregorianCalendar.MONTH),
testdate.getMonth()); // this should pass, but doesn't
database.close();
}
}