When I want to specify specific configuration for the one class, I just have to specify what i want in configuration using
.ObjectClass(typeof(MyClass)).
but what if I have hierarchy of classes? can I specify only root type or I have to specify the every class I have in hierarchy to be sure Db4o works as I expect?
as example, if I want to specify that all classes that I store in the database should update and delete in cascade, can I just write
config.ObjectClass(typeof(object)).CascadeOnUpdate(true); config.ObjectClass(typeof(object)).CascadeOnDelete(true);and be happy?
Although i don't know the answer to precise answer to your question (as I recall specifying only base classes is enough). Why not give it a shot?
However I would like to bring Transparent activation and Transparent persistence to your attention. They are a bit more sophisticated solution to your problem. Or it is not feasible in your project?
Andras
The problem is that some problems can be solved with just adding another (not-base) class to the configuration, what is strange because it is derived from classes that are in configuration.
Also if it would be so simple, then configuration consisting only of 2 lines (ObjectClass(typeof(object))) would solve a lot of problems, but db4o with this configuration does not work at all! (It saves first version of the objects and never updates them, even if they were changed, saved and committed).
That's why it would be nice to to create kind of manual that will explain how this cascading works and were do mistakes can be while working with it.
Thanks about Transparent activation and Persistence -- I know about that and use it where it's possible, but sometimes it's impossible to implement database logic even inside the application persistence layer -- especially when application have to be independent from the database source.
Anyways, thanks for your answer ;-) I was waiting for someone to notice my question more then 2 weeks.
Do you have a piece of simple code which demonstrates the issue?
If you can post it here probably you will get some explanation.
Also, what is your configured updatedepth for the classes?
So, here is example with my explanations. (just to make it more clear)
We have the test class that will illustrate us the point I'm talking about:
class test { public string field; public List<string> array = new List<string>(); public override string ToString() { string res = field+": "; foreach (string str in array) res += str + "; "; return res; } }
configuration is the following:
static IConfiguration configure() { IConfiguration cfg = Db4oFactory.NewConfiguration(); cfg.ObjectClass(typeof(object)).CascadeOnUpdate(true); cfg.ObjectClass(typeof(object)).CascadeOnDelete(true); return cfg; }
I Don't know how should I create configuration as this method is obsolete (I've asked about that in http://developer.db4o.com/forums/th...55239.aspx but still no answers there), so I do it as in tutorial.
the program works this way:
we create the test object and write it state.
test tst = new test(); tst.field = "one"; tst.array.Add("two"); tst.array.Add("three"); Console.WriteLine(tst);
the result is predicatble:
one: two; three;
then we store it to the database, commit, close and destroy all objects:
IObjectContainer cont = Db4oFactory.OpenFile(configure(), "test"); cont.Store(tst); cont.Commit(); cont.Close(); cont = null; tst = null;
After that we open the file, get the object and show what we have:
cont = Db4oFactory.OpenFile(configure(), "test"); tst = cont.QueryByExample(typeof(test))[0] as test; Console.WriteLine(tst);
It's ok, nothing special. then we change it.
tst.field = "another one"; tst.array[0] = "another two"; tst.array.Add("four"); Console.WriteLine(tst);
Now it is the
another one: another two; three; four;
so, we store it back.
cont.Store(tst); cont.Commit(); cont.Close(); cont = null; tst = null;
and when we will get the object back, we'll see that it's not the object we've stored already. It's
another one: two; three;
even if we will close application and open again, we'll see the same line. so, it's the object that is stored in the database.
That is the example I wanted to show you when I was starting this thread. But, as you mentioned in previous post the UpdateDepth, I tried to specify it in the configuration. And if it is great enough (for this test the value 2 is enough), everything works fine!
This is very interesting because with using cascading I was expecting that I will not care about the depth of the tree because logic says (and tutorial proves) that it should get the whole tree. And _IT WORKS_ as it is expected when I specify the names of the classes in the configuration.
cfg.ObjectClass(typeof(test)).CascadeOnUpdate(true);cfg.ObjectClass(typeof(test)).CascadeOnDelete(true);
without specifying depth. And another issue why cascading is required is that sometimes the graph might be bigger than int's range (only theoretically right now).
So, the question is following: why the Db4o works this way while configuration is with typeof(object)?
Can anyone say anything about this issue?
It is a bug in db4o or it's just the thing that I don't understand?
Thanks a lot for your attention.
I see that no one can help me... that's bad....
And I've experienced similar behavior in Java when I was trying to save HashMaps to the database (db4o was storing them perfectly for the first time, but when I was trying to update the HashMap (if the objects in hashMap were changed or new one added/some of them were removed), it stored successfully, but on the next opening it was the same as after first save.
I tried to fix it with specific configuration, but I didn't reach the normal storage behavior.
Still no ideas? Did someone else had such a problems with db4o? or am I the dumbest one here?
This sound too similiar to my problem with .net...http://developer.db4o.com/forums/th...55903.aspx
Did the recommendations Adriano Verona gave you solved your issue?
I'm experiencing this all using Db4o 7.8 (the same might be in 7.10, haven't run all the tests on it.)
But talking about ObjectClass(typeof(object)).CascadeOnUpdate(true), this issue I noticed almost a half of a year ago, and still got no explanations...
nope it didn't help.. and this critcal issue to me - without being able to use collections of objects I will not be able to use db4o.
Did you tried to replace your code with something similar to this?
class Company{
private List<Module> modules;
public IList<Module> Modules{ get{return modules;} }
}
and to work inside the class with this.modules?
Intersting, but i'm not sure how do I work inside the class to store 'modules' as they are still a generic collection of the object.You might be on to somthing, but i'm not sure I understand how to do that.will try I knew what to try :)
But, anyway, my question remains open... :-)
Is it open just for me or for everyone?