views:

992

answers:

9

Do you know of an "easy" way to store and retrieve objects in Java without using a relational DB / ORM like Hibernate?

[Note that I am not considering serialization as-is for this purpose, as it won't allow to retrieve arbitrary objects in the middle of an object graph. Neither am I considering DB4O because of its restrictive license. Thanks.]

"Easy" meaning: not having to handle low-level details such as key/value pairs to rebuild an object graph (as with BerkeleyDB or traditional caches). The same applies for rebuilding objects from a document- or column-oriented DB (CouchDB, HBase, ..., even Lucene).

Perhaps there are interesting projects out there that provide a layer of integration between the mentioned storage systems and the object model (like ORM would be for RDBMSs) that I am not aware of.

Anyone successfully using those in production, or experimenting with persistence strategies other than relational DBs? How about RDF stores?

Update: I came across a very interesting article: A list of distributed key-value stores

+5  A: 

I would suggest Hibernate because it will deal with most of the ugly details that bog developers down when using a database while still allowing for the optimizations that have been made to database software over the years.

Matt Campbell
thanks for your answer, but i just said i *don't* want to use DBs! that implies not using ORMs i guess... i'm looking for alternative stuff. also as i stated in the post, no serialization!!!
frank06
+1  A: 

I'd recommend Hibernate (or, more general, OR-mapping) like Matt, but there is also a RDBMS at the backend and I'm not so sure about what you mean by

...without using a relational DB?...

It also would be interesting to know more about the application, because OR-mapping is not always a good idea (development performance vs. runtime performance).

Edit: I shortly learned about terracotta and there is a good stackoverflow discussion here about replacing DBs with that tool. Still experimental, but worth reading.

Kai
thanks. i meant "take out of the picture RDBMSs and ORMs"
frank06
+1  A: 

Check out comments on Prevayler on this question. Prevayler is a transactional wrapper around object serialization - roughly, use objects in plain java and persist to disk through java API w/o sql, a bit neater than writing your own serialization.

Caveats- with serialization as a persistance mechanism, you run the risk of invalidating your saved data when you update the class. Even with a wrapper library you'll probably want to customize the serialization/deserialization handling. It also helps to include the serialVersionUID in the class so you override the JVM's idea of when the class is updated (and therefore can't reload your saved serialized data).

Steve B.
+3  A: 

NeoDatis looks interesting. It is licensed under the LGPL, so not quite as restrictive as the GLP proper.

Check out their 1 minute tutorial to see if it will work for your needs.

Steve K
thanks steve. i actually know neodatis pretty well (i even wrote warp-persist-neodatis integration) - i just stopped using it because it was really buggy, but i should give it a shot once again. damn i guess i'm being too demanding here... :)
frank06
Were you very involved with the NeoDatis project? Most of the open source project I've been around are fairly responsive to bug reports / patches. I haven't been involved with NeoDatis - so they may be the exception :)
Steve K
yes, *the guy is* quite responsive. but he's alone and problem is i kept on having problems all the time - so i'm not sure about stability. i'm going to check out again now :) and have a look at the source code
frank06
A: 

Hmm... without serialization, and without an ORM solution, I would fall back to some sort of XML based implementation? You'd still have to design it carefully if you want to pull out only some of the objects from the object graph - perhaps a different file for each object, where object relationships are referenced by a URI to another file?

I would have said that wasn't "easy" because I've always found designing the mapping of XML to objects to be somewhat time consuming, but I was really inspired by a conversation on Apache Betwixt that has me feeling hopeful that I'm just out of date, and easier solutions are now available.

bethlakshmi
Isn't this just serialization?
Outlaw Programmer
+3  A: 

I would like to recommend XStream which simply takes your POJOs and creates XML out of them so you can store it on disk. It is very easy to use and is also open source.

willcodejavaforfood
+1, I was going to suggest the same.
skinp
+1  A: 

I still think you should consider paying for db4o.

If you want something else, add "with an MIT-style license" to the title.

orip
i don't think so. thanks for your comment
frank06
A: 

Terracotta provides a highly available, highly scalable persistent to disk object store. You can use it for just this feature alone - or you can use it's breadth of features to implement a fully clustered application - your choice.

Terracotta:

  • does not break object identity giving you the most natural programming interface
  • does not require Serialization
  • clusters (and persists) nearly all Java classes (Maps, Locks, Queues, FutureTask, CyclicBarrier, and more)
  • persists objects to disk at memory speeds
  • moves only object deltas, giving very high performance

Here's a case study about how gnip uses Terracotta for in-memory persistence - no database. Gnip takes in all of the events on Facebook, Twitter, and the like and produces them for consumers in a normalized fashion. Their current solution is processing in excess of 50,000 messages / second.

It's OSS and has a high degree of integration with many other 3rd party frameworks including Spring and Hibernate.

Taylor Gautier
A: 

I guess I have found a sort of answer to my question.

Getting the document-oriented paradigm mindset is no easy task when you have always thought your data in terms of relationships, normalization and joins.

CouchDB seems to fit the bill. It still could act as a key-value store but its great querying capabilities (map/reduce, view collations), concurrency readiness and language-agnostic HTTP access makes it my choice.

Only glitch is having to correclty define and map JSON structures to objects, but I'm confident I will come up with a simple solution for usage with relational models from Java and Scala (and worry about caching later on, as contention is moved away from the database). Terracotta could still be useful but certainly not as with an RDBMS scenario.

Thank you all for your input.

frank06