| By Richard Conway | Article Rating: |
|
| June 2, 2007 05:15 PM EDT | Reads: |
22,790 |
Controlling Object Property Breadth
You may also
want to limit how much data you retrieve from a given object. A complex
object may consist of 20, 30, or even 50 or more properties, including
embedded objects and lists or arrays of objects. What if you only need
access to one or two of those properties? Isn't it overkill to
instantiate the entire object, populating 50 properties in order to get
two of them? If you're retrieving a list of such objects, you could end
up with an array of 200 objects - along with all 50 of their properties
- when all you need or want is one or two properties per object.
What's needed is a mechanism for controlling object property coverage.
One approach is to define a POJO that only defines a subset of the properties in the original object and populate it. This is where a relational database has an advantage over an object database. You can use JDBC to retrieve just the data you want and populate the POJO. "SELECT firstName, LastName FROM PERSON WHERE ID = 1"
Hibernate
Since Hibernate is typically backed by a
relational database, it provides excellent control over your object
property coverage. You can define a SELECT statement that only
retrieves the properties you're interested in and provides them to you
as a Java List or a List of Object Arrays.
DB4O
DB4O is a pure object database, so you must
instantiate the object to access its properties. DB4O provides no help
for you on this score.
Caché
Besides the Object interface that Caché provides, it
also provides an SQL projection or interface. This lets you access
objects as if they were tables and columns in a relational database.
Using this method, Caché provides excellent control over your object
property breadth.
Object Tree Traversal
Once you have your objects,
you want to be able to traverse the object tree. For example, if you
start with an employee, you want to be able to access the company name
as follows:
employee.getDepartment().getCompany().getName().
This is one of the most powerful features of object-oriented development and one of the strongest arguments for using an object database.
Hibernate
Unfortunately relational databases provide
virtually no support for this type of functionality - normally you'd
have to issue SQL SELECTs to retrieve additional data as needed and
create the associated POJOs. Fortunately, Hibernate provides this
functionality for you by providing a proxy object to fetch additional
mapped objects as needed. This works as long as you have a valid
Hibernate session object available.
DB4O and Caché
Since they are object databases to
begin with, DB4O and Caché handle this with aplomb. As you make calls
to related objects, they're automatically retrieved from the database.
Thus you can access your objects as follows:
employee.getDepartment().getCompany().getName();
List myEmployees = department.getEmployees();
And so on.
Enforcement of Referential Integrity
How can you
ensure you don't delete an object that other objects depend on? For
example, can you delete a department if the employees still exist? Does
it support cascade deletes/updates?
Hibernate
While you can define relationships using
Hibernate annotations, the actual support and enforcement of
referential integrity is dependent on the database used on the
back-end.
DB4O
DB4O currently doesn't enforce referential integrity.
Caché
Caché provides full support for maintaining
referential integrity, as well as for performing cascade updates and
deletes. This can be controlled based on the way you define the
relationships. One-to-many relationships enforce referential integrity,
but don't perform cascade updates and deletion. Parent-Child
relationships enforce referential integrity and provide cascade update
and deletion functionality as well.
Enforcement Of Uniqueness
How do you ensure that specific properties are unique in the database, such as Social Security numbers?
Hibernate
Support for marking properties unique and enforcing it is supported by most databases used as a back-end for Hibernate.
DB4O
DB4O currently doesn't provide any support for
enforcing uniqueness. This feature is currently undergoing beta testing
and the tentative release date is round mid-summer 2007.
Caché
You can mark as many properties unique as you want.
Published June 2, 2007 Reads 22,790
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By 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.
![]() |
Stefan Edlich 05/24/07 05:38:44 PM EDT | |||
Hi, Best |
||||
![]() |
Stefan Edlich 05/24/07 05:38:33 PM EDT | |||
Hi, Best |
||||
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?






































