ORM or JDBC?

S

Silvio

What an odd thing to say. The whole point about relational databases is that
their structure is supposed to reflect the innate logical structure of the
data you’re dealing with—the actual semantics of your business app. To want
to abstract away from that would be to abstract away from the very details
of your business.

True. But there are classes of systems other than generic database
management tools for which a relational database is still a generic beast.

One group consists of standard software systems (in the sense of not
custom made and therefore generic) for things like reporting, analysis,
ETL, etc.

Another group consists of systems where users can define complex
entities that need to be (generically) transformed into relational
structures.

In my case users can define/design things like:

-research panels with user defined variable structures and portal user
interfaces
-research questionnaires/surveys where questions have to be mapped to on
screen representations as well as to data representations
-reports and reporting dashboards that have to be able to process data
from one of the above or from third party sources.

I do not only have to handle the RDBMS in a generic way. I use a generic
data access interface that could be mapped onto a RDBMS but in many
cases it can also be mapped to formats like SPSS, Triple-S, DBF, Excel,
CSV etc.

So it just depends on what you are doing.
 
M

Michal Kleczek

Lawrence said:
What an odd thing to say. The whole point about relational databases is
that their structure is supposed to reflect the innate logical structure
of the data you’re dealing with—the actual semantics of your business app.

Of course. But that does not mean that your business app cannot be composed
of parts that are schema independent.
To want to abstract away from that would be to abstract away from the very
details of your business.

Sometimes you need to abstract away the schema. Would you design an ORM tool
with a particular schema in mind?
 
L

Lawrence D'Oliveiro

Would you design an ORM tool with a particular schema in mind?

I wouldn’t use ORM at all. Java already makes it difficult to deal with
databases, without adding unnecessary work like that.
 
M

Michal Kleczek

Lawrence said:
I wouldn’t use ORM at all.

Neither would I :)
But you snipped context (wonder why). Anyway -how about a reporting tool -
would you design it with a particular schema in mind?
 
L

Lew

That's not true. The "whole point" about relational databases is to NOT
reflect the domain structure, but to store data as tables of rows. Prior to
the relational model databases did try to store domain models and it led to
problems, problems so widespread and fundamental that hardly anyone remembers
non-relational databases.

The relational model intentionally breaks the domain model structure into
normal forms of just data, internally devoid of semantics. The genius of the
relational model is that it separated the domain model from the data model,
leaving the mapping between them to a separate layer, the business logic. As
a result, database models capture the data from the domain model, but they
don't reflect the domain model directly.

By design the relational model imposes on the business logic the
responsibility to map the data model to the domain model. ORMs are supposed
to help with that responsibility.
Of course. But that does not mean that your business app cannot be composed
of parts that are schema independent.


Sometimes you need to abstract away the schema. Would you design an ORM tool
with a particular schema in mind?

Would you design a relational schema with only one application in mind?
 
M

Michal Kleczek

Lew said:
That's not true. The "whole point" about relational databases is to NOT
reflect the domain structure, but to store data as tables of rows.

No. RDBMSes do not store data as tables of rows. They _present_ data as
tables of rows (or rather - relations and tuples). The "whole point" about
relational databases is to introduce a "logical model" and abstract away
from "physical model".
What's more - the "whole point" of designing a database schema is to capture
as much relevant information about the domain as possible - the single fact
that you give a name to a relation or specify a constraint means you
_reflect_ the domain structure and _implement_ business logic.
If that was not the case all database schemas would be equivalent (and EAV
would be the most used one).
Prior
to the relational model databases did try to store domain models and it
led to problems, problems so widespread and fundamental that hardly anyone
remembers non-relational databases.

I've never heard hierarchical databases tried to store domain models. Could
you point me to some material backing this statement?
The relational model intentionally breaks the domain model structure into
normal forms of just data, internally devoid of semantics. The genius of
the relational model is that it separated the domain model from the data
model,
leaving the mapping between them to a separate layer, the business logic.
As a result, database models capture the data from the domain model, but
they don't reflect the domain model directly.

Of course they don't. Neither do class models of applications using a
database.
By design the relational model imposes on the business logic the
responsibility to map the data model to the domain model.

At least we agree that a data model and an (OO) application class model are
different and have to be mapped.
But the question of whether one or the other is _the_ domain model cannot be
answered - they are equal. Furthermore - every application accessing the
same database has _its own_ class model that is suited for _this_
application.
ORMs are
supposed to help with that responsibility.

But they fail to do so because they require a class model and a database
model to too closely mirror each other and this contradicts their purpose.
Would you design a relational schema with only one application in mind?

It depends :)
Why this question?
 
L

Lew

No. RDBMSes do not store data as tables of rows. They _present_ data as
tables of rows (or rather - relations and tuples). The "whole point" about
Sure.

relational databases is to introduce a "logical model" and abstract away
from "physical model".

Well, I agree with that but still stand by my picture. Both "whole points",
and why I put the expression in quotes, are far from the whole point. Both
are valid points from a programmer's toolbox of ontologies.
What's more - the "whole point" of designing a database schema is to capture
as much relevant information about the domain as possible - the single fact
that you give a name to a relation or specify a constraint means you
_reflect_ the domain structure and _implement_ business logic.
If that was not the case all database schemas would be equivalent (and EAV
would be the most used one).

Yes, you are right.
I've never heard hierarchical databases tried to store domain models. Could
you point me to some material backing this statement?

I was putting a touch of poetic license in there, and also I was thinking of
network-model databases. These tried to capture all the relevant
relationships directly, rather than in the ad hoc fashion of the (pure)
relational model.

But you are correct - all these representations whether object or data are
reflections of the domain model, essentially projections of an /n/-dimensional
model space to an /m/-dimensional data or object model, where /m < n/.
Poetically speaking, of course.

We're all six blind men examining the elephant here.
Of course they don't. Neither do class models of applications using a
database.

You are correct.
At least we agree that a data model and an (OO) application class model are
different and have to be mapped.

I agree with nearly all of what you're saying.
But the question of whether one or the other is _the_ domain model cannot be
answered - they are equal. Furthermore - every application accessing the
same database has _its own_ class model that is suited for _this_
application.
Indeed.
But they fail to do so because they require a class model and a database
model to too closely mirror each other and this contradicts their purpose.

They don't require that. This is what's not in "almost all". It's a bit
tedious to construct an example, but for the category of projects for which
JPA (I excoriate other ORMs) suits, it imposes no restraints on the data model
whatsoever, and the entity model is constrained by the semantic model and
somewhat by the data model, which transitively depends on the semantic model.
I don't know what you mean by "too closely", but I really cannot conceive of
a normal business-type project where JPA plays a role in deciding the object
or data models. On the contrary, those flow from normal design and
development processes, and JPA is an implementation tool to connect the two.

....
It depends :)
Why this question?

To show that it's a similar question, and that the answer is, "It depends."

Usually a relational schema for a larger project supports more than one
application, e.g., inventory and order fulfillment share data. The parts of
the system interact with the parts of the schema that they need, and the
schema serves all parts.

Likewise an ORM tool assumes a kind of meta-schema - the (appearance of) a
relational data store. It's as general for the intended use as it needs to
be, that is, it allows all kinds of things that fit its meta-schema. Just
like a relational database schema permits all kinds of things, not all known
at the beginning, if they fit.

Using JDBC on a per-project basis is designing an ORM tool for one particular
database schema. That tool is your data-access layer for that project.

Both are excellent questions, for their respective domains of discourse. They
are part of the design and implementation question list one must generate for
a project.

You make well-reasoned, empowering points.
 
M

Michal Kleczek

Lew said:
Well, I agree with that but still stand by my picture. Both "whole
points",
and why I put the expression in quotes, are far from the whole point.
Both are valid points from a programmer's toolbox of ontologies.


Yes, you are right.



I was putting a touch of poetic license in there, and also I was thinking
of
network-model databases. These tried to capture all the relevant
relationships directly, rather than in the ad hoc fashion of the (pure)
relational model.

But you are correct - all these representations whether object or data are
reflections of the domain model, essentially projections of an
/n/-dimensional model space to an /m/-dimensional data or object model,
where /m < n/. Poetically speaking, of course.

We're all six blind men examining the elephant here.



You are correct.



I agree with nearly all of what you're saying.

So if we are mostly in agreement I'm going to try to move further :)
They don't require that. This is what's not in "almost all". It's a bit
tedious to construct an example, but for the category of projects for
which JPA (I excoriate other ORMs) suits, it imposes no restraints on the
data model whatsoever, and the entity model is constrained by the semantic
model and somewhat by the data model, which transitively depends on the
semantic model.
I don't know what you mean by "too closely", but I really cannot
conceive of
a normal business-type project where JPA plays a role in deciding the
object
or data models. On the contrary, those flow from normal design and
development processes, and JPA is an implementation tool to connect the
two.

(BE WARNED: below you're going to find controversial ideas described by a
lot of people as "bad engineering practices" - but please read the whole
thing before criticizing :) )

Imagine you have two models: a database schema S and a class library C. Both
are completely independent and both capture a certain aspect of the system
under design.
I would consider ORM useful if it helps me to "map" one to another to create
an application that meets some set of requirements. To be precise "mapping"
means moving data from the db to instances of classes from library C
(potentially creating instances of those classes) and back to save the state
of those instances in the database.

Now imagine schema S desribes an accounting database and library C - classes
implementing neural network computations. There is no single class related
to accounting in the library C. The only connection between accounting and
neural networks is the application under design - it provides the necessary
context. The question: does it make sense to use ORM to do the "mapping"?

Then imagine library C is a GUI widget library. Does it make sense to use
ORM in this case? It would be sooo convinient to be able to write:

void main(String[] args) {
EntityManager em = ...;

JFrame f = em.find(JFrame.class, "main");
f.show();

while(true) {}
}

and use ORM parametrization and "magic" to map S (accounting database
schema) and C (UI classes) to have accounting UI without pain :)
(Yes - I know the above is taking ORM to the extreme - but it is _just_ to
illustrate the weaknesses of current ORMs in mapping _arbirary_ schemas to
_arbitrary_ class models).

What supporters of JPA say instead is that it is a "good practice" to create
another class model B (so called "business model") then use ORM to "map" the
database schema to class model B and then write more code to "map" class
model B to class model C. The problem is that there is no application
specific "business logic" I could put into B since all of it is already
implemented in C.

There is even more "insanity" - once we have class model B - we start using
data binding library based on reflection (Java Beans conventions) to move
data from instances of B to instances of C - loosing the last inteded
benefits of having B (namely type safety).

[snip]
Using JDBC on a per-project basis is designing an ORM tool for one
particular
database schema. That tool is your data-access layer for that project.

As soon as I get an ORM tool capable of mapping to _arbitrary_ class model I
am going to use it wholeheartedly. Until that happens I think I would just
stick to more lightweight tools such as Spring JDBC that resolves some
inconvinience of JDBC (connection/resource management etc.) while still
giving me freedom with designing my class model.
 
L

Lew

Michal said:
Now imagine schema S desribes an accounting database and library C - classes
implementing neural network computations. There is no single class related
to accounting in the library C. The only connection between accounting and
neural networks is the application under design - it provides the necessary
context. The question: does it make sense to use ORM to do the "mapping"?

It depends.

If you have entities that are modeled in the database, it makes sense.
Then imagine library C is a GUI widget library. Does it make sense to use
ORM in this case? It would be sooo convinient to be able to write:

void main(String[] args) {
  EntityManager em = ...;

  JFrame f = em.find(JFrame.class, "main");
  f.show();

  while(true) {}

}

and use ORM parametrization and "magic" to map S (accounting database
schema) and C (UI classes) to have accounting UI without pain :)
(Yes - I know the above is taking ORM to the extreme - but it is _just_ to
illustrate the weaknesses of current ORMs in mapping _arbirary_ schemas to
_arbitrary_ class models).

If you don't have an ORM map to intermediate entities, then you have
to manually map to those entities.

If you "map" directly from the DB to your widget, you are still
mapping to the entity represented by the widgete. Since you are dead
set against modeling that domain entity as anything other than a set
of related tables or a set of related widgets, you're right, an ORM
will be of no use. But that's not because you are saving any
mapping effort. You've just traded the effort of an entity model for
the sometimes greater effort of maintaining widget-to-table mappings
by hand.
What supporters of JPA say instead is that it is a "good practice" to create
another class model B (so called "business model") then use ORM to "map" the
database schema to class model B and then write more code to "map" class
model B to class model C. The problem is that there is no application
specific "business logic" I could put into B since all of it is already
implemented in C.

Fine.

There is even more "insanity" - once we have class model B - we start using

It is appropriate that you put "insanity" in quotes here, since the
real thing you attempt to disparage is not actually insane.
data binding library based on reflection (Java Beans conventions) to move
data from instances of B to instances of C - loosing the last inteded
benefits of having B (namely type safety).

Why would you do that? It's not a JPA thing.
As soon as I get an ORM tool capable of mapping to _arbitrary_ class model I
am going to use it wholeheartedly. Until that happens I think I would just

You mean like JPA, then.

Well, strictly speaking what it maps to is arbitrary *entity* models,
which is far more useful.

It actually is not useful to map to arbitrary class models. Just as
'enum' doesn't handle every type-safe enumeration scenario, JPA is not
even intended to handle *every* data-access scenario.

THERE IS NO LIBRARY THAT WILL DO WHAT YOU ASK, NOR CAN THERE EVER BE.

That's like saying, "Until clean energy gives me a perpetual-motion
machine I will stay with fossil fuels." It's a ridiculous
precondition.

JPA is only intended for the subset of mappings that make sense.
You're asking for one that doesn't make sense, then deriding ORMs for
not supporting it. So don't use an ORM. It's not even meant for
everything.

So, "It doesn't do everything" is a bullshit complaint.
stick to more lightweight tools such as Spring JDBC that resolves some
inconvinience of JDBC (connection/resource management etc.) while still
giving me freedom with designing my class model.

Making JPanel a domain object for an accounting system is an abuse of
freedom. But you go, girl!
 
M

Michal Kleczek

Lew said:
Michal said:
Now imagine schema S desribes an accounting database and library C -
classes implementing neural network computations. There is no single
class related to accounting in the library C. The only connection between
accounting and neural networks is the application under design - it
provides the necessary context. The question: does it make sense to use
ORM to do the "mapping"?

It depends.

If you have entities that are modeled in the database, it makes sense.
Then imagine library C is a GUI widget library. Does it make sense to use
ORM in this case? It would be sooo convinient to be able to write:

void main(String[] args) {
EntityManager em = ...;

JFrame f = em.find(JFrame.class, "main");
f.show();

while(true) {}

}

and use ORM parametrization and "magic" to map S (accounting database
schema) and C (UI classes) to have accounting UI without pain :)
(Yes - I know the above is taking ORM to the extreme - but it is _just_
to illustrate the weaknesses of current ORMs in mapping _arbirary_
schemas to _arbitrary_ class models).

If you don't have an ORM map to intermediate entities, then you have
to manually map to those entities.

If you "map" directly from the DB to your widget, you are still
mapping to the entity represented by the widgete. Since you are dead
set against modeling that domain entity as anything other than a set
of related tables or a set of related widgets, you're right, an ORM
will be of no use.

That's not the point. As we agreed before - each application has its own
class model. One application does some computing using neural networks - its
class model will be neural networks related. Another app's purpose is to
present a user with a GUI - its class model will be GUI widgets.

To make ORM useful it has to support both without requiring creating
_another_ class model just to be able to use ORM.
But that's not because you are saving any
mapping effort. You've just traded the effort of an entity model for
the sometimes greater effort of maintaining widget-to-table mappings
by hand.

But mapping from "entity model" to widgets has the same cost as mapping DB
schema to widgets. So having "entity model" incures additional cost of
mapping between it and DB schema (and additionally maintaining "entity
model" itself).
It is appropriate that you put "insanity" in quotes here, since the
real thing you attempt to disparage is not actually insane.


Why would you do that? It's not a JPA thing.

But that is a very common practice - once you have a set of Java beans you
use Java Beans based data binding tool to display data from those Java
beans.
You mean like JPA, then.

Well, strictly speaking what it maps to is arbitrary *entity* models,
which is far more useful.

What I'm doing here is actually questioning the need of such "entity
models". I'm trying to prove that they exist solely because a designer made
a decision to use ORM. Hence I talk about accidental complexity.
It actually is not useful to map to arbitrary class models. Just as
'enum' doesn't handle every type-safe enumeration scenario, JPA is not
even intended to handle *every* data-access scenario.

I would say more - its usfullnes is very limited at all.
THERE IS NO LIBRARY THAT WILL DO WHAT YOU ASK, NOR CAN THERE EVER BE.

JPA is marketed as such unfortunatelly.

OTOH there are libraries that will help me to do it (the mapping) instead of
making it more difficult.
 
L

Lawrence D'Oliveiro

Now imagine schema S desribes an accounting database and library C -
classes implementing neural network computations.

Then imagine library C is a GUI widget library.

You mean C is both a library of GUI widgets and a library implementing
application logic?

I would not do things that way.
What supporters of JPA say instead is that it is a "good practice" to
create another class model B (so called "business model") then use ORM to
"map" the database schema to class model B and then write more code to
"map" class model B to class model C. The problem is that there is no
application specific "business logic" I could put into B since all of it
is already implemented in C.

If C is the GUI, then there is a case for putting the application logic into
a lower layer B.
 
L

Lawrence D'Oliveiro

Leif Roar said:
No, the main point of relational databases is to store, change and search
large amounts of data in a way that both protects the integrity of the
data and has good performance.

But that “integrity†is part of the semantics of the data.
A good match between the business semantics and the relational data-model
is certainly a good way to protect the developers' sanity (such as it is)
but that's not the purpose or intent of a relational database. Database
normalisation will often serve to move the data-model _away_ from the
semantic model, and relational DB concepts such as cursors, row locks,
foreign keys and joins are downright alien to the semantic model.

On the contrary: normalization, foreign keys and joins are part of the
mathematical formalism that is specifically designed to express that
semantics.
 
S

Silvio

[snip]

(BE WARNED: below you're going to find controversial ideas described by a
lot of people as "bad engineering practices" - but please read the whole
thing before criticizing :) )

Imagine you have two models: a database schema S and a class library C. Both
are completely independent and both capture a certain aspect of the system
under design.
I would consider ORM useful if it helps me to "map" one to another to create
an application that meets some set of requirements. To be precise "mapping"
means moving data from the db to instances of classes from library C
(potentially creating instances of those classes) and back to save the state
of those instances in the database.

Now imagine schema S desribes an accounting database and library C - classes
implementing neural network computations. There is no single class related
to accounting in the library C. The only connection between accounting and
neural networks is the application under design - it provides the necessary
context. The question: does it make sense to use ORM to do the "mapping"?

Then imagine library C is a GUI widget library. Does it make sense to use
ORM in this case? It would be sooo convinient to be able to write:

void main(String[] args) {
EntityManager em = ...;

JFrame f = em.find(JFrame.class, "main");
f.show();

while(true) {}
}

and use ORM parametrization and "magic" to map S (accounting database
schema) and C (UI classes) to have accounting UI without pain :)
(Yes - I know the above is taking ORM to the extreme - but it is _just_ to
illustrate the weaknesses of current ORMs in mapping _arbirary_ schemas to
_arbitrary_ class models).

What supporters of JPA say instead is that it is a "good practice" to create
another class model B (so called "business model") then use ORM to "map" the
database schema to class model B and then write more code to "map" class
model B to class model C. The problem is that there is no application
specific "business logic" I could put into B since all of it is already
implemented in C.

There is even more "insanity" - once we have class model B - we start using
data binding library based on reflection (Java Beans conventions) to move
data from instances of B to instances of C - loosing the last inteded
benefits of having B (namely type safety).

[snip]
Using JDBC on a per-project basis is designing an ORM tool for one
particular
database schema. That tool is your data-access layer for that project.

As soon as I get an ORM tool capable of mapping to _arbitrary_ class model I
am going to use it wholeheartedly. Until that happens I think I would just
stick to more lightweight tools such as Spring JDBC that resolves some
inconvinience of JDBC (connection/resource management etc.) while still
giving me freedom with designing my class model.

Well, this is more or less my take on the subject. I rarely go to the
trouble of explaining it in this length since, as you said, most people
tend to think we have it all backwards...
 
A

Arved Sandstrom

But that “integrity†is part of the semantics of the data.


On the contrary: normalization, foreign keys and joins are part of the
mathematical formalism that is specifically designed to express that
semantics.

I agree, partly. IDEF1 (IDEF1X), for example, is a _semantic_ data
model, and it makes use of primary and foreign keys, and a variety of
relationships. It's entirely semantic to say that one instance of entity
A has a relationship to N instances of entity B, and that a certain set
of attributes of B matches the primary keys of certain instances of A
(foreign key); it becomes a relational database model when we express
that particular relation (and all others in the model) as a set of
n-tuples. However, if I've set up an IDEF1 semantic data model I don't
have to proceed to using a relational model, and although it may not
seem intuitive a relational model is not even a "natural" one to
gravitate towards; it's just the one that gets picked a lot.

Normalization is something else - that's not semantics. It's a technique
for taking a relational database model and turning it into something
practical for use inside an RDBMS. At an even more detailed levels,
cursors and row locks _are_ in fact relational *DB* concepts, not
relational concepts, which distinction was made by Leif.

As for data integrity, that's another topic. I've seen beautiful
3NF/BCNF schemas loaded with extra constraints that still had no data
integrity, because the client application code was defective and was
loading up the tables with crap. Do you have data integrity if 217 table
rows in 5 different tables have perfect consistency in the relational
sense, but 44 of those rows are garbage data in the real world? In fact,
a finely-tuned RDBMS will help you maintain your relationships as you
insert or update or delete that garbage. :)

AHS
--
That's not the recollection that I recall...All this information is
certainly in the hands of the auditor and we certainly await his report
to indicate what he deems has occurred.
-- Halifax, Nova Scotia mayor Peter Kelly, who is currently deeply in
the shit
 
A

Alessio Stalla

On 03/28/2011 04:53 PM, Michal Kleczek wrote:





[snip]
(BE WARNED: below you're going to find controversial ideas described bya
lot of people as "bad engineering practices" - but please read the whole
thing before criticizing :) )
Imagine you have two models: a database schema S and a class library C.Both
are completely independent and both capture a certain aspect of the system
under design.
I would consider ORM useful if it helps me to "map" one to another to create
an application that meets some set of requirements. To be precise "mapping"
means moving data from the db to instances of classes from library C
(potentially creating instances of those classes) and back to save the state
of those instances in the database.
Now imagine schema S desribes an accounting database and library C - classes
implementing neural network computations. There is no single class related
to accounting in the library C. The only connection between accounting and
neural networks is the application under design - it provides the necessary
context. The question: does it make sense to use ORM to do the "mapping"?
Then imagine library C is a GUI widget library. Does it make sense to use
ORM in this case? It would be sooo convinient to be able to write:
void main(String[] args) {
   EntityManager em = ...;
   JFrame f = em.find(JFrame.class, "main");
   f.show();
   while(true) {}
}
and use ORM parametrization and "magic" to map S (accounting database
schema) and C (UI classes) to have accounting UI without pain :)
(Yes - I know the above is taking ORM to the extreme - but it is _just_to
illustrate the weaknesses of current ORMs in mapping _arbirary_ schemasto
_arbitrary_ class models).
What supporters of JPA say instead is that it is a "good practice" to create
another class model B (so called "business model") then use ORM to "map" the
database schema to class model B and then write more code to "map" class
model B to class model C. The problem is that there is no application
specific "business logic" I could put into B since all of it is already
implemented in C.
There is even more "insanity" - once we have class model B - we start using
data binding library based on reflection (Java Beans conventions) to move
data from instances of B to instances of C - loosing the last inteded
benefits of having B (namely type safety).
Using JDBC on a per-project basis is designing an ORM tool for one
particular
database schema.  That tool is your data-access layer for that project.
As soon as I get an ORM tool capable of mapping to _arbitrary_ class model I
am going to use it wholeheartedly. Until that happens I think I would just
stick to more lightweight tools such as Spring JDBC that resolves some
inconvinience of JDBC (connection/resource management etc.) while still
giving me freedom with designing my class model.

Well, this is more or less my take on the subject. I rarely go to the
trouble of explaining it in this length since, as you said, most people
tend to think we have it all backwards...

I think you're both missing a key point: OR mapping is not done just
for the sake of mapping - to bring data straight from the DB to the
GUI and vice-versa. Were it true, then I'd agree that ORMs do not add
any value.
Instead, ORMs exist because most people find it useful to represent
the domain model as "something" which is neither the DB, nor the GUI.
I'm not advocating OO as The Only True Way, but if one chooses Java
(and thus OO), that's basically the main way. So the objective of the
OO programmer is: let's reason about the domain using a class-based
model. Such a model is "pure", it exists in isolation, it is a library
with no interaction with the outside world - at least, it should be.
The OO domain model is the core of the application. While the GUI is
replaceable, the DB is replaceable, etc. the domain model is not - if
you replace it (with a sufficiently different one), you get a
different application. Then, given that everything gravitates around
the domain model, you need every other piece of the application to
talk to it. For GUIs, this means data binding (and a service layer for
client-side GUIs with a server counterpart). For RDBMSes, this means
ORM. For XML, this means JAXB or other mapping technologies, etc. etc.

If you skip the domain model part, and pretend the GUI is the model of
your application, then you're simply not doing Object-Oriented
Programming. That is not a crime, mind you, but then I don't
understand why you're using Java in the first place.

Alessio
 
M

Michal Kleczek

Alessio said:
I think you're both missing a key point: OR mapping is not done just
for the sake of mapping - to bring data straight from the DB to the
GUI and vice-versa. Were it true, then I'd agree that ORMs do not add
any value.
Instead, ORMs exist because most people find it useful to represent
the domain model as "something" which is neither the DB, nor the GUI.
I'm not advocating OO as The Only True Way, but if one chooses Java
(and thus OO), that's basically the main way. So the objective of the
OO programmer is: let's reason about the domain using a class-based
model. Such a model is "pure", it exists in isolation, it is a library
with no interaction with the outside world - at least, it should be.
The OO domain model is the core of the application. While the GUI is
replaceable, the DB is replaceable, etc. the domain model is not - if
you replace it (with a sufficiently different one), you get a
different application. Then, given that everything gravitates around
the domain model, you need every other piece of the application to
talk to it. For GUIs, this means data binding (and a service layer for
client-side GUIs with a server counterpart). For RDBMSes, this means
ORM. For XML, this means JAXB or other mapping technologies, etc. etc.

That is a view that I shared for quite some time. But I stopped shortly
after I became a happy owner of my own programming business and I REALLY had
to start counting time (hence money) spent on development and maintanance of
software artifacts.

I think there are several flaws in the approach you suggest and I'll try to
list them:

1. In reality there is no "one true domain model" - each application (or
part of the application) has not only _its own_ view of the problem domain
but actually has _its own_ notion of what the problem domain is.
And this is a primary way of _decoupling_ - this is why we can create
reusable components. Otherwise we would not be able to create a GUI library
that is independent of any other class library. We would not be able to
create a servlet container without coupling it to so called "business domain
class model"
You would not want Swing or Tomcat to be coupled to accounting would you?

(Also note that looking at the system as a whole - Swing or Tomcat are
_part_ of it - not something external).

2. Java as a language is much less convinient to describe certain aspects of
a system - for example SQL is way better in data management and Mathematica
language in linear programming. So it is a matter of choosing the right tool
for the job - split your system into _independent_ problem domains (such as
GUI, networking, data management and sharing, linear programming, accounting
etc), develop solutions for each using tools the most apropriate for a
specific problem domain and then integrate them.
If you find Java apropriate to solve a given problem - fine. But it does not
mean it is apropriate to solve other problems as well. The same reasoning is
for different Java class libraries solving different problems.

3. Specifically - it is much cheaper to force various applications (or parts
of a single application) to share a single view of data that is described as
a database schema than it is to force them to share the same view of data
using a Java class library ("so called" domain model). It is like this for
various reasons - one of the most important is - there is much more tools to
integrate various languages/environments with a RDBMS than to integrate them
with Java. You don't want to develop those tools by hand.

4. There is no way you can create a class library that is a "rich domain
model" and is suitable for all aspects of the system - simply because you
would have to implement all aspects of the system in this library (and you
don't want to mix GUI and accounting in the same library, do you). Once you
start removing business logic from it you will end up with an "anemic domain
model" that in the end is not useful at all.

If you skip the domain model part, and pretend the GUI is the model of
your application, then you're simply not doing Object-Oriented
Programming.

Of course I am. I'm just choosing different abstractions (the most suitable
to solve the problem in hand). How is GUI less OO than accounting logic?
That is not a crime, mind you, but then I don't
understand why you're using Java in the first place.

See above. I'm using Java where it makes sense.
 
S

Silvio

That is a view that I shared for quite some time. But I stopped shortly
after I became a happy owner of my own programming business and I REALLY had
to start counting time (hence money) spent on development and maintanance of
software artifacts.

That may be it. I have been in the same position for over 15 years now.
Perhaps that is why we look at this a bit differently.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top