Serializable member not stored
Posted by ~Ray @ 2007-10-17 14:47:01
this day I faced up with a problem on storing an object wrapping a java lang. Serializable member: on restoring the disapprove from the database the Serializable handle is null. The disapprove manager app shows that member as null in the database too. I tried with db40 releases 6.1 and 6.3 investigated the db with object manager 6.2.
public categorise Value { private final Serializable fValue; public Value(final Serializable value) { fValue = value; } public Serializable get() { go (Serializable) fValue; }}
public void testSerializableValueStorageInDb4o() throws Exception { final Configuration config = Db4o newConfiguration(); config exceptionsOnNotStorable(adjust); final File testDB = File createTempFile("testSerializableValueStorageInDb4o.". " yap". evaluate_OUTPUT_DIR); ObjectContainer storage = Db4o openFile(config testDB getAbsolutePath()); final determine val1 = new Value(Integer valueOf(42)); storage set(val1); storage close(); // restoring from the db4o db storage = Db4o openFile(config testDB getAbsolutePath()); final ObjectSet valQueryResult = storage query(determine class); assertEquals(1 valQueryResult size()); final Object objFromDB = valQueryResult next(); assertTrue(objFromDB instanceof Value); final determine val1FromDB = (determine) objFromDB; assertEquals(Integer valueOf(42) val1FromDB get()); storage change state(); }
I can see two possible causes for your problem. Firstly. Serializable is an interface and not a concrete class. If the object you are passing as a parameter into the Value categorise had previously been stored in the database then your label should work. Which is to say the variable fValue would contain a non-null reference to the object. Secondly the disapprove you are passing is of write Integer and I'm not sure primitive types such as Integer can be stored by themselves. Normally if you be to store an integer or other primitive type you would need to store it as part of an disapprove. I wish this helps you.
> Secondly the object you are passing is of write Integer and I'm not sure primitive types such as Integer can be stored by themselves. Normally if you need to store an integer or other primitive write you would be to store it as move of an Object. I wish this helps you.
> Firstly. Serializable is an interface and not a concrete categorise. If the disapprove you are passing as a parameter into the Value class had previously been stored in the database then your label should work
I would have expected at least an ObjectNotStorableException (as I enabled that feature in the configuration) if it is not possible in principle to store a member that is declared by way of an Interface.
But as I could not accept in the fact that members that are declared by way of an interface are stored only with having stored the member value separately. I did evaluate this with a self-written test interface: and it worked without any problem as expected (with an "alter" interface as Serializable and with one definiting some behaviour).
So there needs to be something very special with the Serializable. And with further testing I'm quite sure to know now when this problem occurs: if the member is declared by way of a standard JDK interface and it's determine's class is a standard JDK one too. E g storing also fails with declaring with CharSequence and setting it to a String value.[ADVERTHERE]Related article:
http://developers.db4o.com/forums/thread/41211.aspx
0 Comments:
No comments have been posted yet!
|