Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to save persistent objects to the file system

I'd like to save persistent objects to the file system using Hibernate without the need for a SQL database.

Is this possible?

like image 757
Ben Crowhurst Avatar asked Jan 04 '12 11:01

Ben Crowhurst


4 Answers

Hibernate works on top of JDBC, so all you need is a JDBC driver and a matching Hibernate dialect.

However, JDBC is basically an abstraction of SQL, so whatever you use is going to look, walk and quack like an SQL database - you might as well use one and spare yourself a lot of headaches. Besides, any such solution is going to be comparable in size and complexity to lighweight Java DBs like Derby.

Of course if you don't insist absolutely on using Hibernate, there are many other options.

like image 114
Michael Borgwardt Avatar answered Nov 09 '22 05:11

Michael Borgwardt


It appears that it might technically be possible if you use a JDBC plaintext driver; however I haven't seen any opensource ones which provide write access; the one I found on sourceforge is read-only.

like image 39
mcfinnigan Avatar answered Nov 09 '22 07:11

mcfinnigan


You already have an entity model, I suppose you do not want to lose this nor the relationships contained within it. An entity model is directed to be translated to a relational database.

Hibernate and any other JPA provider (EclipseLink) translate this entity model to SQL. They use a JDBC driver to provide a connection to an SQL database. This, you need to keep as well.

The correct question to ask is: does anybody know an embedded Java SQL database, one that you can start from within Java? There are plenty of those, mentioned in this topic:

  • HyperSQL: stores the result in an SQL clear-text file, readily imported into any other database
  • H2: uses binary files, low JAR file size
  • Derby: uses binary files
  • Ashpool: stores data in an XML-structured file

I have used HyperSQL on one project for small data, and Apache Derby for a project with huge databases (2Gb and more). Apache Derby performs better on these huge databases.

like image 24
parasietje Avatar answered Nov 09 '22 06:11

parasietje


I don't know exactaly your need, but maybe it's one of below:

1 - If your need is just run away from SQL, you can use a NoSQL database.
Hibernate suports it through Hibernate OGM ( http://www.hibernate.org/subprojects/ogm ). There are some DBs like Cassandra, MongoDB, CouchDB, Hadoop... You have some suggestions Here .

2 - Now, if you want not to use a database server (with a service process running always), you can use Apache Derby. It's a DB just like any other SQL, but no need of a server. It uses a singular file to keep data. You can easily transport all database with your program.
Take a look: http://db.apache.org/derby/

3 - If you really want some text plain file, you can do like Michael Borgwardt said. But I don't know if Hibernate would be a good idea in this case.

like image 36
RicardoS Avatar answered Nov 09 '22 07:11

RicardoS