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 4535272
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:23:05+00:00 2026-05-21T14:23:05+00:00

Assuming that i’m new about the topic DTO. I can’t understand if it is

  • 0

Assuming that i’m new about the topic DTO.
I can’t understand if it is correct to use the DTO in tandem with JSF, Spring and Hibernate.
Let me explain, so far I have used the entity bean, created directly from the database, both in business layer and in the presentation layer.
Now I decided to try using the DTO approach, but I can not understand how they can help.
For example if I have two classes User and Message, and a user has more messages associated; how can I populate the DTO from the database? Or do I manually populate the DTO at the business layer?
can someone post an example on how to use DTO?

Thank you in advance.
Regards,
Roberto

  • 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-21T14:23:05+00:00Added an answer on May 21, 2026 at 2:23 pm

    DTO stands for Data Transfer Object. It’s supposed to be a plain vanilla Javabean class without any API/architecture specific restrictions such as JSF, JPA or Spring annotations. I.e. it should not contain any import or FQN pointing to an external API. The sole goal is to be able to pass data between different architectures of a big modular webapplication.

    For example, if you don’t want to use a JPA/Hibernate entity bean as model property of a JSF managed bean and view because they may not be passed beyond the EJB class due to some overly restrictive business or modularity reasons, then you need to create a copy of this class and map the loose properties yourself. Basically:

    UserEntity userEntity = em.find(UserEntity.class, id);
    UserDTO userDTO = new UserDTO();
    userDTO.setId(userEntity.getId());
    userDTO.setName(userEntity.getName());
    // ...
    return userDTO;
    

    There are plenty of libraries available which makes bean-to-bean mapping easy in following way:

    SomeLibary.map(userEntity, userDTO);
    

    However, for the average webapplication you don’t need DTOs. You’re already using JPA entities. You can just go ahead with using them in your JSF bean/view.

    This question alone already indicates that you actually don’t need DTOs at all. You are not blocked by some specific business restrictions. You should not then search for design patterns so that you can apply it on your project. You should rather search for real problems in form of overcomplicated/unmaintainable/duplicated code so that you can ask/find a suitable design pattern for it. Usually, refactoring duplicate code almost automatically introduces new design patterns without you actually realizing it.

    A good example is when a JPA entity is "too large" for the particular purpose (i.e. the entity contains way much more properties than you actually need). Having a lot of those partially used entities is a waste of server memory. To solve this, you could create a DTO class/subclass based on only a few of its properties which you create and fill using constructor expression in JPQL.

    See also:

    • DAO and JDBC relation?
    • JSF Controller, Service and DAO
    • JSF Service Layer
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming that Runtime.getRuntime().addShutdownHook(new Thread() has been set up correctly, how can the ShutdownHook thread
Assuming that I have to write to a binary file. I can use the
Assuming that the two are compatible, how can I force Maven 2 to use
Assuming that best practices have been followed when designing a new database, how does
Assuming that I know there is a git-daemon running at git://git.mycompany.com , how can
Assuming that CompareAndSwap (or CAS) never fails spuriously, can CompareExchange be implemented with CAS?
assuming that I know nothing about everything and that I'm starting in programming TODAY
Assuming that I want to use a hash as an ID instead of a
Assuming that T is an arbitrary type and we're talking about Objective-C. Then what
Assuming that I have an entity which is mapped with Hibernate ( E )

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.