Do ORMs "make SQL databases suitable for OO programming style"? In the
sense that an ORM presents tuples derived from RDBMS data as OO
programming language objects, that's true. But those initial datalayer
objects are frequently PODSs, or very close, and a number of OO styles
advocate keeping datalayer objects as essentially bundles of fields with
accessor methods.
If I use ORM I expect that it can reasonably deal with deep structures.
Normalizing the data model at object level is exactly not what I want.
As to the other main function of an ORM, which is to present a
supposedly simpler way of accessing an RDBMS than JDBC, I think it's
arguable as to whether any of that exemplifies high levels of the OO
art: most of it (not just in Java) looks pretty procedural to me.
Hmm, you see ORM not as a function extension but simply as a more
convenient API to RDBMS. That's OK. But maybe _O_RM does not hit the
nail on the head in this case.
I'll posit that a relational data model does very often fit.
Well, maybe it fits because we mostly think in solutions rather than in
requirements. This applies already to the customer requests. It is often
difficult to distinguish between real requirements and creative ideas of
the customer, how to solve his issues.
If you get two steps back, then there are quite often requirements that
do not fit well into RDBMS. I.e. I had almost no project where not at
least one property of some object had a 1:n relation. I do not talk
about classical relations like costomer-supplier here - they fit well
into RDBMS. I talk about properties that can have more than one value.
Case #1: enumeration types with multiple selections.
To put them into a RDBMS you need either
a) introduce a new table,
b) serialize them into a string or bit vector or
c) put each value into a separate column.
Each choice has it's disadvantages. a) adds complexity to SQL (many
JOINs, difficult updates - OK, here ORMs can really help) and has a
large overhead for small integral types, because of the foreign keys and
the row management of the DBMS. c) and b) only works if the number of
different values is finite by design. b) cannot be reasonably indexed.
c) makes it really complicated to add a new value.
Within a OO data model I simply add an array or a set to the class and I
am done.
Case #2: multiple values without a limited set (e.g ingredients, allergens)
Here can only use solution a) from above in the RDBMS. If you have a
dozen properties of this type things get really worse. Or you end up with
d) a transposed data model.
But d) is even worse with respect to indices and does not provide type
safety because the RDBMS can't handle polymorphism directly.
I also have seen solutions with
e) one transposed table for each data type.
Now the RDBMS is finally raped.
We've just
had a few generational cycles of young bucks who are trying to make
their name by challenging something that works. Use a non-relational
model when you've knowingly proved that there is no way of making your
data fit relational - don't jump on non-relational because it's
currently cool.
Of course, that's always true.
But from my experience success is not manly a question whether you have
gone one way or the other. It is more a question if you have done this
well and in you have enough experience with the tools you are using.
Err, if it's not true in general, then it's maybe not usually true? So
it's "known" by whom?
I think, I used the wrong wording. Let's call it a preconception.
By regarding your data as being document-oriented you already made a
fundamental decision that your data is semi-structured or
non-structured.
Well, an XML is a document too, and most of the time it is well structured.
And most people who seize on a NoSQL solution were probably never
"stuck" with an SQL DB, they just got sucked in by the hype. I've heard
way more stories about projects where folks had to program
relational-like logic on top of a NoSQL DB to solve their problems than
I've heard anecdotes about people not being able to make things work
with an RDBMS.
I do not really have experience with NoSQL databases. But I used non
relational data models and in memory computing now for about 6 years in
different projects. None of the projects failed, all are still live.
Also we did not really save resources because of the decisions made. But
from the code maintenance and from the performance point of view it was
successful. Some change requests to the first of these projects were
implemented by an apprentice in half an hour. This would have taken a
few days by a qualified programmer, if we had chosen a relational data
model.
In the last project - a larger one - we have significant performance
benefits. There is an adjacent third party application with a very
similar data model from the customers point of view. (They are better
with respect to inheritance, we are better with respect to deep
structures but both can deal with polymorphism, table properties an so on.)
They ended up with solution d). We use XML documents. Measurements show
about three orders of magnitude performance difference, measured in time
per object access. We have two CPU cores with <30% load if users make
traffic. They have 16 CPU at 80-100% load if users make traffic. The
number of objects and attributes is comparable. In fact the data is
partially synchronized by interfaces. Both are Web applications. The
number of users is comparable.
OK, they have chosen PHP (used in an object oriented way), we have .NET
3.5. But this will not explain all the 3 orders of magnitude. Their
system creates heavy load on the large attribute values table.
Marcel