52

What is the difference between graph-based databases (http://neo4j.org/) and object-oriented databases (http://www.db4o.com/)?

6 Answers 6

41

I'd answer this differently: object and graph databases operate on two different levels of abstraction.

An object database's main data elements are objects, the way we know them from an object-oriented programming language.

A graph database's main data elements are nodes and edges.

An object database does not have the notion of a (bidirectional) edge between two things with automatic referential integrity etc. A graph database does not have the notion of a pointer that can be NULL. (Of course one can imagine hybrids.)

In terms of schema, an object database's schema is whatever the set of classes is in the application. A graph database's schema (whether implicit, by convention of what String labels mean, or explicit, by declaration as models as we do it in InfoGrid for example) is independent of the application. This makes it much simpler, for example, to write multiple applications against the same data using a graph database instead of an object database, because the schema is application-independent. On the other hand, using a graph database you can't simply take an arbitrary object and persist it.

Different tools for different jobs I would think.

3
  • I would say in the different way: you can do everything with object oriented databases as with the the graph databases and more in more efficient way, but usually object oriented databases are more complex.
    – Slider
    Commented Apr 2, 2018 at 20:25
  • A graph database can be emulated with classes/objects (nodes) and associations/references/pointers (edges) using object oriented database abstractions.
    – Slider
    Commented Apr 2, 2018 at 20:34
  • Object database can certainly have bi-directional relationships and referential integrity. Objectivity/DB has supported both since 1989. I'm not sure why you've decided that schema for an object database must be tied to the application and the schema for a graph database is independent of any application. They are both just databases containing persisted data. There may or may not be applications associated with either kind of database, or they may both be run in a no-code environment.
    – djhallx
    Commented Jun 22, 2022 at 13:07
14

Yes, the API seems like the major difference, but is not really a superficial one. Conceptually a set of objects will form a graph and you could think of an API that treats this graph in a uniform way. Conversely, you could in theory mine a generic graph structure for patterns and map them to objects exposed via some API. But the design of the API of an actual product will generally have consequence on how data is actually stored, how it can be queried, so it would be far from trivial to, say, create a wrapper and make it look like something else. Also, an object-oriented database must offer some integrity guarantees and a typing structure that a graph database won't normally do. In fact, serious OO database are far from "free form" :)

Take a look at [HyperGraphDB][1] - it is both a full object-oriented database (like db4o) and a very advanced graph database both in terms of representational and querying capabilities. It is capable of storing generalized hypergraphs (where edges can point to more than one node and also to other edges as well), it has a fully extensible type system embedded as a graph etc.

Unlike other graph databases, in HyperGraphDB every object becomes a node or an edge in the graph, with none-to-minimal API intrusion and you have the choice of representing your objects as a graph or treating them in a way that is orthogonal to the graph structure (as "payload" values of your nodes or edges). You can do sophisticated traversals, customized indexing and querying.

An explanation why HyperGraphDB is in fact an ODMS, see the blog post Is HyperGraphDB an OO Database? at Kobrix's website.

9

As Will descibes from another angle, a graphdb will keep your data separated from your application classes and objects. A graphdb also has more built-in functionality to deal with graphs, obviously - like shortest path or deep traversals.

Another important difference is that in a graphdb like neo4j you can traverse the graph based on relationship (edge) types and directions without loading the full nodes (including node properties/attributes). There's also the choice of using neo4j as backend of an object db, still being able to use all the graphy stuff, see: jo4neo This project has a different approach that could also count as an object db on top of neo4j: neo4j.rb. A new option is to use Spring Data Graph, which gives graphdb support through annotations.

The same question was asked in the comments to this blogpost.

1

From a quick browse of both their websites:

The major difference is the way the APIs are structured, rather than the kind of free-form database you can build with them.

db4o uses an object mapping - you create a Java/C# class, and it uses reflection to persist it in the database.

neo4j has an explicit manipulation API.

Neo4j seemed, in my humble opinion, much nicer to interact with.

You might also consider a key-value store - you could make exactly the same free-form database with one of those.

1

The difference at low-level is not so huge. Both manage relationships as direct links without costly joins. Furthermore both have a way to traverse relationships with the Query language, but the graph database has operators to go recursively at Nth level.

But the biggest difference is in the domain: in a Graph databases all is based on the 2 types: vertexes and edges, even if usually you can define your own types as a sort of subtypes of Vertex or Edge.

In the ODBMS you have no Vertex and Edge concepts, unless you write your own.

1
  • In an object database every class type is node, edge, or both. A Person class with an attribute "friends" which is a list of references to a class FriendOf which contains two references to Person types and a date attribute "metOn" would be an edge. Instances of the Person class are both objects and nodes in the database and instances of the FriendOf are both objects and edges in the database.
    – djhallx
    Commented Jun 22, 2022 at 13:16
-3

With graph databases, you have a slight semblance of a chance that it is based on mathematical graph theory. With Object-oriented databases, you have the certainty that it is based on nothing at all (and most certainly no mathematical theory at all).

Not the answer you're looking for? Browse other questions tagged or ask your own question.