0

I have a database in which i have a huge table, when i retrieve data from this table in need to split the data into a few classes (think of them as some kind of categories) instead of a class that is mapped to the table. There is an simple easy to do this? Would be better recieve all that data from the database into the class mapped to the table and the split it?

EDIT: I forgot to mention this: which one would be more efficient?

Example:

myTable
-------------------------------------------------------------------------------------------
id | someInt 1| some varchar[ ] |  etc some cols... |Date| some other int|some other varchar
-------------------------------------------------------------------------------------------
^                              ^                    ^                                     ^
|______________________________|                    |_____________________________________|
       Category 1 (ClassA)                                     Category n(ClassN)
2
  • If the table is huge, it would be better not to load the entire table into memory. Any other answer would need more information, e.g. what do you mean by "split". Show examples. Why load it all? What is the end goal and what would you do if table is so big it won't fit in memory? Commented Oct 6, 2015 at 18:52
  • @Andreas i don't want to load all the data from the table, just select some rows with a query and then split the data in other java classes Commented Oct 6, 2015 at 18:55

1 Answer 1

4

Whether or not I'm using an ORM, I would still prefer to keep one entity class that maps directly to the database table. That would essentially be a bean with nothing but getters and setters on it that can be used with whatever DAOs you have implemented.

The other objects you are talking about I would refer to as "domain objects". These can wrap the entity bean (composition) I mentioned above and would provide domain-specific view and operations on that entity. This separation of domain from entity also leads to more modular code.

This has the added benefit of not exposing your entity beans to any client modules that want to make use of your domain objects.

Good luck!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.