File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes How to achieve transparency layers using ORM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How to achieve transparency layers using ORM" Watch "How to achieve transparency layers using ORM" New topic

How to achieve transparency layers using ORM

ajay mittal

Joined: Nov 23, 2011
Posts: 24
Hi All,

Currently i am using ORM through hibernate in a project where i have two options while designing my data models and its mapping with db tables.

1. Create the data models a replica copy of tables in db, so that while using hibernate i can easily map each row to a object in java. but leads me to a large size of data in db. Which can be a performance hindrance parameter
after 1-2 years.

2. I can create data models by using my own explicit logic on objects obtained from db, in this case also i will use hibernate but i have to create my own new data models for internal functioning of application after using data from data models mapped to certain tables in db. This will even reduce size of my tables to a great extent and will not cause any performance hindrance but this will break the ORM pattern partially because it will give be objects but i have to convert them into one useful for my application logic.

Please suggest me the write approach to be used.

Emanuel Kadziela
Ranch Hand

Joined: Mar 24, 2005
Posts: 187
I don't understand why having a data model in your code be a replica of tables in db increases the size of the database. If the database architecture is done correctly, the database is not de-normalized in some erroneous way, than the amount of data should not be affected by how you map it through ORM. Perhaps the database architecture needs to be re-evaluated. Can you give an example of why you think you will have a larger size of data and negative performance impact if you choose option 1?

Option 2 sounds like you are asking for trouble. Perhaps it's the way you described it, but it seems to me you are proposing to introduce another data translation layer in your code.
I agree. Here's the link:
subject: How to achieve transparency layers using ORM
It's not a secret anymore!