Re: How to implement simple DB persistence
tnorgd wrote:
I see all of you recommend using an existing tool rather than creating
a new one. OK, so I keep thinking of it. What would you suggest to
satisfy my following criteria:
- should be small. I checked that for Hibernate I have to download
56MB of compressed archive...
Robert Klemme wrote:
So it's small, isn't it?
Particularly if you compare that to what you need if you don't
download Hibernate.
I am slightly puzzled by the OP's obsession with Hibernate. You can
do find with just JDBC and your flavorite favor of RDBMS (such as
Derby or Postgres). However you still need to map your object model
to your relational one, and a good object-relational mapper (ORM) tool
like Hibernate or EclipseLink or OpenJPA takes care of a lot of the
scut work for you.
Again, you don't need JPA or any other ORM to use a database from
Java. Read up on JDBC if you're comfortable with that approach. With
JDBC you don't use XML or annotations; everything is laboriously hand-
crafted into the code. With JPA you have a choice to mix and match
varying degrees of XML and annotation magic.
ORM or raw JDBC, either way you can pretty much plug in the database
of your choice. With JPA you hide the connection details in an XML
(gasp!) file called "persistence.xml" or "orm.xml". With Tomcat and
other app servers you hide the connection information in an XML
(gasp!) file such as "context.xml".
tnorgd wrote:
- must not use XML - I personally hate it. I would love to use
annotations or some text format for configurations (e.g. yaml)
I want to drive a car but I don't want to use a garage for
maintenance. I personally hate it. I would love to use my own timing
light, tools, lift, ratchet wrench, computerized engine-diagnostic
unit, left-handed stembolt cutter, ...
Robert Klemme wrote:
XML *is* a text format. But yes, you can uses JPA with annotations and
can probably get by without any XML. However, you are making your life
unnecessary hard by turning down what nowadays is an industry standard
(I mean XML of course).
tnorgd wrote:
- data stored in the resulting SQL tables must be human-readable. It
must be possible to log directly into a database and run an SQL query,
browse the results, etc.
Robert Klemme wrote:
AFAIK this is possible with all RDBMS.
That is correct, Robert. I thought by "human-readable" the OP had
meant something different, but given his explanation shown here, it's
clear that not only relational but all database management systems
(DBMSes) with a JDBC driver fulfill the requirement.
tnorgd, anything you use would have to meet this last requirement
trivially. The whole freaking point of a DBMS is to persist data,
preferably with some integrity guarantees. That means that any
interface to the DBMS, be it their own query tool, a third-party SQL
client, ODBC access, JDBC access or what-have-you, must be able to
access the data regardless of which of those interfaces induces
changes.
Likewise the whole freaking point of JDBC is to connect a Java program
to a DBMS in a (nearly) portable fashion, segregating business logic
into the Java side and data matters into the DBMS side. Any solution
you use, JPA or not, will ultimately rest on JDBC calls. That's what
they're for.
For the DBMS I recommend Derby or Postgres. Others have spoken
favorably of H2 and SQLLite. YMMV.
--
Lew