Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A few questions about working with db4o

Tags:

.net

db4o

I am trying the db4o object databse and so far I quite like what I am seeing, but I also read this post on stackoverflow db4o experiences? indicating that not everything that seems so easy is easy.

Right now, I have some questions regarding on how db4o is used in real world apps. So if you have any experience in working (especially in web app context) with db4o, I would love to hear them.

Here are my questions:

  1. How do you manage object identity when working with db4o stored objects?**
    Coming from RDBMS background where you normally always have a primary key / identity column for every table, I cant imagine right now on how to manage object identity in db4o.

    For example, if I was working with NHibernate / mysql and needed to find a User object by id, I would do session.Load(primaryKey) and it will be retrieved by its PK. It is also very common that the PK is defined as auto increment in the table definition.

  2. As there is no such option in db4o, my thought was using a Guid struct in order to identify some objects in the object database.

  3. Any tools to view the stored objects in the db?

    Is there something like SQL Server Management Studio (probably less sophisticated) in the db4o world? I would like to view the already stored data / objects in the db file.

  4. Are you screwed when renaming your domain objects?

    As far as I know when you rename a class, any previously stored instances in the db cannot be retrieved anymore. Is there a way to work around this issue? How do you deal with updates against a live database which already contains many objects?

  5. Can I exclude properties from being saved to the DB?

    If for example one domain object holds a reference to a (stateless) service object, then the service object will also be persisted if the domain object gets persisted, right?

It seems a bit odd to have a service instace saved in the database, at least to me.

Can you exclude the service instance from being saved? If the domain object is retrieved again, how can I make sure that the service is also injected in the instance again?

like image 477
Max Avatar asked Oct 25 '09 08:10

Max


2 Answers

1) How do you manage object identity when working with db4o stored objects? In db4o you have normally no id. db4o uses the object-identity to distinguish the object apart. So the same object in memory is going to be the same object for the database.

As long a you don't serialize object this works fine. However as soon as objects are serialized / disconnected this doesn't work anymore. For example in a web-scenario: You send the data to the browser. Now you need to identify the objects later again by some ids.

I think this three options are possible: - Use the db4o internal id. However this id isn't forever. Defragmenting the database changes this id. - Using db4o's UUIDs. But db4o UUIDs are quite large - Creating ids by yourself

2) There's a Object-Manager Tool to look at the database. However it extremely limited in its current state. In my opinion this is a huge drawback for db4o.

3) You can create aliases, rename classes and fields etc. However changing the inheritance-hierarchy doesn't work. Then you need to copy the old data to new instances.

4) Yes. You can mark fields as transient with the .NET-NonSerialized attribute or custom attributes.

like image 60
Gamlor Avatar answered Oct 14 '22 18:10

Gamlor


In objects oriented databases (such as db4o) object identity should not really be used. Instead one used queries and navigation. First perform a query to get one/some objects, then use navigation to get to others.

'Navigation' means that you just follow the fields/references in any loaded object.

Using object identifiers can be considered bad style, most application (that I know) don't use them at all.

like image 22
TilmannZ Avatar answered Oct 14 '22 19:10

TilmannZ