Comments
paul.nowak wrote: Matt, thanks for the comments. I made an error on the version of Plone. It's 2.5 Plone running on Zope 2.9x. In regards to the additional products, we have a skin installed and we have a product that we had custom developed for us that connects to a PostgreSQL database. We've looked at slow PostgreSQL queries causing problems and have not been able to find an issue. We've also tested for the case where the PostgreSQL server is down and have not been able to create an issue. We therefor...
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


Evaluating Options for Persisting Java Objects
Hibernate, DB4O, and Caché Database with Jalapeño

We live in a relational world - which is too bad since we develop with objects. Since most non-trivial applications require information to be persisted and retrieved in what is generically called a database, we need to find efficient methods for persisting our objects and retrieving them. Historically, this has been done with relational databases and lots of code that flattens the objects and maps them to the relational tables. This can be done in Java or with object-relational mapping tools like Hibernate.

While most books and articles about object-oriented software development discuss the benefits of using objects to describe the problem space, currently most development is done in a more convoluted manner, working from both the Java and database ends and using various technologies to bridge the gap between them. Hibernate has emerged as one of the most popular ways to address this development challenge.

Instead of starting with a database schema and building objects from the tables and data therein, this article will focus on starting with the Java objects and evaluate a few of the many options for persisting them. We will compare and contrast the methods, as well as discuss challenges and problems specific to object persistence management (see Table 1).

Options for Persisting Java Objects
There are many options for persisting your Java objects. Some are best used when your persistence needs are simple (such as saving program state between sessions) and some are better when your needs are complex (such as saving lots of data over long periods of time). Some applications simply need to load data for use in configuring the application, while others require sophisticated tools for searching and filtering object sets. The latter is typical for applications that use a database for persistence and will be the primary focus here. For each project you work on, you should evaluate which persistence strategy best fits your needs based on the project requirements. The following persistence mechanisms will be discussed in this article:
• Hibernate
- The most commonly used object-relational mapping tool
• DB4Objects DB4O
- A small simple embeddable object database
• InterSystems' Caché Database with Jalapeño
- An enterprise database that lets you store POJOs via its Jalapeño technology - but also provides a JDBC/SQL interface to the objects stored in the database

Please note that there are many other object-relational mapping solutions and object databases available, the purpose of this article is simply to provide some insight as to the benefits of using these technologies versus a JDBC/DAO implementation, how they compare and to how you can use them for your projects.

Definition: DataStore - A system for storing and retrieving data. Can be relational or object-oriented.

Object Persistence Mechanism Considerations
For each of the persistence strategies outlined above, I will review the following:
• Ease of Implementation
- How much preparation and/or configuration is required to persist your objects?
• Ease of Persisting Objects
- How do you persist an object or objects?
- Is it straightforward and intuitive?
- Is it better/simpler/faster than using SQL and writing DAOs?
• Ease of Retrieving Objects
- What mechanisms are available for finding and retrieving the objects in the datastore?
• Control over Object Depth
- How many objects do you want to save or retrieve at the same time?
• Control over Object Property Breadth
- How many properties do you need access to? Can you only return those properties?
• Object Tree Traversal
- Can you access all related objects and their properties simply by traversing the object tree?
• Enforcing Referential Integrity
- How do you ensure you don't delete an object that other objects depend on?
* For example, can you delete a department if employees still exist?
- Does it support cascade deletes/updates?
• Enforcing Uniqueness
- How do you ensure that specific properties are unique in the database, such as Social Security numbers?
• Support for Indices
- Can you define indices that will enhance the performance of your queries?
• Property Constraints
- Can you control/limit the values that will be entered into the datastore?
• Security and Access Control
- How do you control who has access to the data and what they can do with it?

Ease of Implementation
One of the things we're trying to get away from is the effort to write and maintain DAOs. So let's look at what's involved in setting up your datastore and prepping your POJOs to be persisted for each of the persistence mechanisms identified.

Hibernate
Hibernate has the most complex setup of the solutions discussed here, but it's not that bad and Hibernate does provide a lot of tools to make your life easier. There are multiple ways to implement Hibernate, but since we are starting the POJOs, we'll only consider the case of adding annotations to the Java class to support Hibernate persistence. If you're using Hibernate 3.2 with Java 1.5 or above, you can use annotations to map your POJO properties to your Table columns. Using annotations is much less verbose than defining your mappings in XML files and has the additional benefit of reducing the number of files you must keep track of. In addition to annotating your POJOs you need to provide the fully qualified name of the annotated class as a <mapping> element in the hibernate.cfg.xml file.

The minimal steps for preparing to persist your objects with Hibernate are:
1)  Set up a database and create a username and password for Hibernate to access it with
2)  Annotate your Java Classes
3)  Add your class mappings, database, and user/login information to the hibernate.cfg.xml file
4)  Run the Hibernate hbm2ddl to create the schema in the database

An example of mapping in the hibernate.cfg.xml file:

<mapping class="com.egrok.hibernate.Person"/>


About Richard Conway
Richard Conway is a software developer and technology consultant with more than 15 years of technology, project management, and information services experience. He has extensive experience developing Java/Struts-based web applications. He started focusing more on Swing based developments at the beginning of 2005 and has just finished a Swing-based client/server asset management project. He lives in Miami with his wife Patricia, is currently working on an EMR application, and plays sand volleyball in his spare time.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Hi,
your article is very well done. However one point:
>DB4O doesn't provide any support for constraints.
The is only partially true.
It's more then easy to implement this in just a few simple lines using db4o callbacks.

Best
Stefan Edlich
(Author of "The Defintive Guide to db4o" Apress)

Hi,
your article is very well done. However one point:
>DB4O doesn't provide any support for constraints.
The is only partially true.
It's more then easy to implement this in just a few simple lines using db4o callbacks.

Best
Stefan Edlich
(Author of "The Defintive Guide to db4o" Apress)


Your Feedback
Stefan Edlich wrote: Hi, your article is very well done. However one point: >DB4O doesn't provide any support for constraints. The is only partially true. It's more then easy to implement this in just a few simple lines using db4o callbacks. Best Stefan Edlich (Author of "The Defintive Guide to db4o" Apress)
Stefan Edlich wrote: Hi, your article is very well done. However one point: >DB4O doesn't provide any support for constraints. The is only partially true. It's more then easy to implement this in just a few simple lines using db4o callbacks. Best Stefan Edlich (Author of "The Defintive Guide to db4o" Apress)
Enterprise Open Source Magazine Latest Stories . . .
This is a deal that has been around for all of this year, and I know the NYC-based guy charged with pulling the technical pieces together. He has been looking at software platforms for months and separating contenders from pretenders based on the criteria he's established. To my knowle...
3Leaf Systems, the well-funded start-up, dropped its fig leaf Tuesday and took a running jump into the pools of memory, I/O and cache that it can construct and deconstruct at will based on the application, creating scale-up shared-memory SMP systems the likes of mainframes, proprietary...
Funambol, a provider of open source mobile cloud sync and push email for billions of phones, today announced it has acquired Zapatec, Inc., a leader of AJAX web 2.0 frameworks. The acquisition enables Funambol to uniquely address the industry pervasive device fragmentation challenge th...
Plone and Drupal are two leading open source Content Management Systems (CMS). Both were recognized in the 2009 Open Source CMS awards, run by Packt Publishing. Both also have large installed bases and large developer communities. This is made evident by some quick searching on Googl...
SOASTA, a provider cloud testing, today announced that performance engineers can now build web application tests in Apache JMeter, the most popular open source load testing tool, and run them in SOASTA's Global Test Cloud. Deploying JMeter tests to the Cloud has been a complex, time-co...
Yahoo! Inc. (Nasdaq:YHOO), a leading global Internet company, took its second major step in five months towards open-source cloud computing today, debuting an open source version of Traffic Server, a high performance application server for builders of cloud services. Traffic Server ena...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE