Aritz
Aritz

Reputation: 31649

Integrating JCR into my application

I'm building a JSF-Spring-Hibernate based application which needs to store content as pdf, MS Office files, etc. I was thinking about providing it JCR capabilities, adding Jackrabbit or Modeshape i.e. However I still have some doubts.

PD: My servlet container is Tomcat 6.

Pool your ideas!

Upvotes: 2

Views: 1178

Answers (1)

Randall Hauch
Randall Hauch

Reputation: 7187

You've stated that you're already relying upon Hibernate and MySQL to store most of your data and storing files on the file system. What are you hoping that JCR might bring to the table? What is it about Hibernate, MySQL, and/or the file system that is not sufficient? Is your current architecture difficult to scale or cluster? Do you having concurrency problems writing the same file? Are your entity classes to restrictive? Do you're entities form a hierarchy, since this is often difficult with Hibernate and a relational database?

There has to be some reason why you'd consider changing your current architecture to add in a whole new data storage technology.

Let's imagine that you would like to just store the file content inside the JCR repository instead of on the file system. Yes, that would work, and it would likely simplify your application a bit and make it easier with less code. But is that benefit worth the complexity of adding in a JCR implementation to your application? (Only you can answer this.)

Or are you also considering using JCR instead of Hibernate. Some find that hard to imagine, but in some cases (especially when your entities are mostly map-like data structures anyway) JCR actually can store information much more cleanly than Hibernate.

Store your data inside JCR means that each "entity" is represented with a node and properties (and possibly child nodes for more complex entities), and that those entities would be stored in a hierarchical structure. You could do all of this while using a generic node type (like nt:unstructured), or you could choose to define a node type for each type of entity. With mixin types and residual property definitions you can even allow the nodes for a single type of entity to vary in the kind of information they hold: all customer nodes might contain a customer ID, first name, last name, and a few other bits of information, but some customers have additional information (membership ID, memberSinceDate, etc.) that you only need to add to the appropriate customer nodes. As your requirements change over time, the data stored on the nodes can easily evolve with it, sometimes without even having to modify your node types (which, BTW, can be done dynamically without restarting your application or if you planned ahead without requiring you to change your application code).

In short, using JCR as a database gives you tremendous amounts of flexibility, even after your application has been developed. It frees you from having to define explicit classes with fixed fields for your data entities, and it allows your application to be more concerned with what information is appropriate for a specific entity instance.

In summary, just using JCR to store the files is probably overkill - it sounds like you've already got entities that store the metadata about the files. The way you describe your architecture, you would not really be benefiting from any of the best features of JCR. That makes me think that JCR is simply not a great fit for your current architecture - you seem to have implemented most of the functionality yourself.

Upvotes: 2

Related Questions