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.
posted 3 years ago
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.