Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4074128
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:07:27+00:00 2026-05-20T17:07:27+00:00

What is the general idea to help deciding when to use DTO and when

  • 0

What is the general idea to help deciding when to use DTO and when to use Entity in these cases ?

  1. UI / server side java calling the services. Should it get / send entities or DTOs ?
  2. Web service calling the services. Should the services accept entities or DTOs ?

I like reading the code that pass entities around :

  1. simpler to pass around, no need to map to DTOs
  2. dont need extra classes
  3. relations to other entities are already defined, so dont need combine related DTOs into one DTO
  4. just POJOs

But there are arguments about DTO that maps to an entity is safer, because it’s a contract, and the entity can change to whatever form, and the DTO will stay the same. For example, like the entity has a field name, and the DTO also has a field name. Later on, if the requirement changes, the database table changes, the entity can change also, changing name into firstName and lastName. But the DTO will still have a field name, which is firstName + lastName.

So here’s the list of the pros of using DTOs :

  1. backward compatible from the viewpoint of the code that accepts the DTOs

The cons of DTO i can think of is :

  1. have to define the DTO classes and the mapping (perhaps using dozer)
  2. the programmers would have to analyze when to use DTO and entity, i mean passing DTO for every methods is a mess
  3. overhead of conversion of entities to DTOs and vice versa
  4. I’m still unsure about the one-to-many relationship on how to map them. In JPA we can lazy initialize this, but when passing in DTO, should i initialize this or not. Shortly, DTOs cant have lazy initialized proxies, only contains values.

Please share you thoughts ..

Thank you !

Here are some quotes from different places

pro dto :

Reuse of the entity class as a DTO
seems messy. The public API of the
class (including annotations on public
methods) no longer clearly defines the
purpose of the contract it is
presenting. The class will end up with
methods that are only relevant when
the class is being used as a DTO and
some methods that will only be
relevant when the class is being used
as an entity. Concerns will not be
cleanly separated and things will be
more tightly coupled. To me that is a
more important design consideration
then trying to save on the number of
class files created.

pro entity :

Absolutely NOT!!!

JPA entities are mapped to a database,
but they are not ‘tied’ to a database.
If the database changes, you change
the mappings, not the objects. The
objects stay the same. That’s the
whole point!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T17:07:28+00:00Added an answer on May 20, 2026 at 5:07 pm

    I would go for the DTO option for the following reasons:

    • The service interface should be independant of the database, a change in one should not always require a change in the other.
    • You are making an assumption that your services will always be called by a Java client
    • Using lazy loading when the object is on the otherside of a web service call does not work well.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following entity (not exact but gives a general idea): @Entity public
this wiki page gave a general idea of how to convert a single char
I'm just trying to get a general idea of what views are used for
General tutorial or good resource on how to use threads in Python? When to
In general, what kinds of design decisions help an application scale well? (Note: Having
I was just wondering the general idea how the embedded Google Analytics Javascript works?
Maybe what I am trying to accomplish is not feasible but the general idea
I'm trying to figure out if i have the general idea behind the assignment
The title is pretty bad but heres the general idea of what I want
General Follow the same standards for all tests. Be clear about what each test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.