File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Domain Objects with IDs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Domain Objects with IDs" Watch "Domain Objects with IDs" New topic
Author

Domain Objects with IDs

Patrick Davenport
Greenhorn

Joined: May 12, 2009
Posts: 10
I'm currently working on a Domain Object model. To me the idea of putting a BigInteger in the object for database tracking is wrong. The domain object should not know about its persistence mechanism. I thought about making the actual domain objects all abstract. The database objects would all extend the domain objects. In actually the code would use the implementation versions at runtime, but the model is programmed to the interfaces.

However, I've never seen this done. Is it a good idea?
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1


>>To me the idea of putting a BigInteger in the object for database tracking is wrong.


Why? Let's hear your reasoning. Indeed, Java objects can be uniquely identified without an id, but we do need to bend a little to address the reality of a database. Is this too much bending?

>>The domain object should not know about its persistence mechanism.


Having an id doesn't map an object to a particular database or persistence mechanism. If anything, it simply recognizes the fact that the data will, at some point, be persisted.

I thought about making the actual domain objects all abstract.


It's a beautiful design. Abstraction is elegance when it comes to Java design. But the purpose of abstraction is flexibility and plug-ability. Is this your goal? I'm not so sure if it is, or for that matter, if it will ultimately help you achieve your goal.

There is a balance between elegant design and simplicity. Sometimes simple is good. I hate seeing reams of code with all these BaseClass, BaseClassImpl classes. It just looks so doggone ugly, and it's needless. Don't add needless complexity to a simple design problem.

Just my opinion.

-Cameron McKenzie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Domain Objects with IDs