phanin
phanin

Reputation: 5487

Parsing the result-set in DAO vs Service layer

Let's consider a use-case of loading a map with from the db.

Even though I use Hibernate, my use-case doesn't require the whole student entity, which is huge, to be loaded. I just need the above pair of values.

When I execute plain sql query using the Hibernate, the response is in the format of List .

Here's my questions.

Q) Should the parsing of that raw result-set take place in DAO layer or Service layer?

My opinion is that as I'm not executing any business logic (like filtering one of those students), the method in the DAO layer itself should parse those results, construct the map, and return that pairs.

Any other insights or fundamentals reg DAO vs Service layer would be highly appreciated.

Upvotes: 1

Views: 344

Answers (1)

Brad Gardner
Brad Gardner

Reputation: 1627

The rule of thumb I use is:

Only return from your data layer exactly what your service layer is going to use. So in this case, I would parse the list and build your map before returning. All your service layer is interested in is the map so why bother with the rest?

Upvotes: 2

Related Questions