db4o Developer Community

db4o open source object database, native to Java and .NET
Welcome to db4o Developer Community Sign in | Join
in Search
More Search Options

Basic problem with store and retrieve

Last post 11-25-2008, 09:13 PM by mmoore99. 4 replies.
Sort Posts: Previous Next
  •  11-21-2008, 11:22 PM 52118

    Basic problem with store and retrieve

    Attachment: Db4oTest.zip

    I am a db4o newbie and am having a problem successfully completing the basic operation of persisting an object and having the retrieval of that object return data matching the original object.  The test shown in the code below fails on the assert statement highlighted in bold.  The value in retrievedObject.CheckinFlightSegment.DepartureDateTime.TimeZone is not populated in the retrieved object even though it was populated in the original object that was stored.

    I have attached a zip with the following files:

    1. OriginalObject.jpg - Screen capture of debug watch window showing originalObject immediately before storing in the database.
    2. RetrievedObject.jpg -  Screen capture of debug watch window showing retrievedObject immediately after retrieving from the database.
    3. TestDatabase.db - Db4o database after completion of the test.
    4. UnitTestSessionCapture.jpg - Screen capture showing the unit test result at the point of failure.
    5. Db4oTest.cs - The test source code (essentially same as shown below).

    I would appreciate any assistance in determining why this process isn't working correctly.  If there is any additional information that is needed, please let me know.

     [Test]
    public void Db4oTest
    {
        string dbFileName = "TestDatabase.db";
        IObjectContainer db = null;
        
        //ensure that we are starting with a clean database
        if(File.Exists(dbFileName)) File.Delete(dbFileName);
        
        //configure and open the database
        Db4oFactory.Configure().ObjectClass(typeof(Checkin)).CascadeOnUpdate(true);
        Db4oFactory.Configure().ObjectClass(typeof(Checkin)).CascadeOnActivate(true);
        db = Db4oFactory.OpenFile(dbFileName);

        //create the object to be persisted
        Checkin originalObject = createCheckin();

        //persist the object and close the database
        db.Store(originalObject);
        db.Commit();
        db.Close();

        //re-open the database and retrieve the object
        db = Db4oFactory.OpenFile(dbFileName);
        IObjectSet queryResult = db.QueryByExample(typeof(Checkin));
        Checkin retrievedObject = (Checkin) queryResult[0];

        //validate the retrieved object
        Assert.AreEqual(originalObject.CheckinId, retrievedObject.CheckinId);
        Assert.AreEqual(originalObject.CheckinFlightSegment.DepartureDateTime.TimeZone,
                                  retrievedObject.CheckinFlightSegment.DepartureDateTime.TimeZone);

        db.Close();
    }

     

  •  11-21-2008, 11:29 PM 52119 in reply to 52118

    Re: Basic problem with store and retrieve

    In my previous message I failed to mention that I get the same test results when using both v7.4 and v7.7 of the .Net 3.5 versions of db4o.
  •  11-22-2008, 12:36 AM 52120 in reply to 52119

    Re: Basic problem with store and retrieve

    mmoore99:
    In my previous message I failed to mention that I get the same test results when using both v7.4 and v7.7 of the .Net 3.5 versions of db4o.

     

    Upon further review, when I run the test in Post #1 of this thread using db4o v7.7 the program crashes with an IndexOutOfRange exception when the "db.store(originalObject)" command is executed.  A screen capture of the unit test session showing the error is attached.


  •  11-24-2008, 07:20 AM 52136 in reply to 52118

    Re: Basic problem with store and retrieve

    I tried the simplest possible testcase with datetime and it passed. I used db4o 7.4.68 as currently it is the most stable release.

    can you please try

    Db4oFactory.Configure().ActivationDepth(int.MaxValue);

    before you reopen the db and check if it still fails

    and secondly it would be good if you do not use automatic fields as you may face issue when retrieving data using soda queries.

  •  11-25-2008, 09:13 PM 52160 in reply to 52136

    Re: Basic problem with store and retrieve

    db4o.supporter:

    can you please try 

    Db4oFactory.Configure().ActivationDepth(int.MaxValue);

    Thanks for your suggestion.  Inserting the command to configure the activation depth did indeed solve the problem.  After going through the tutorial and reading the documentaion I thought that setting the activation would not be required since I had specified:

    Db4oFactory.Configure().ObjectClass(typeof(Checkin)).CascadeOnActivate(true);
     I guess I need to go back and do some further reading to understand the difference between cascading and activation depth.
View as RSS news feed in XML