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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:38:28+00:00 2026-06-09T09:38:28+00:00

I am developing a simple forum web application using SpringMVC, JPA2. I have created

  • 0

I am developing a simple forum web application using SpringMVC, JPA2.
I have created JPA entities like User, Forum, Post etc which reflects the DB table structure.

But while displaying the data on UI I need DTOs as I can’t always hold the data to be displayed on UI using Entities.

For ex: Change Password screen. Here I need to hold Old Pwd, New Password and Confirm New Pwd. But User entity won’t have Old/New/Confirm Pwd fields, it just has Password. So I need to create DTOs which are just data carriers between Web and service layers.

My question is while creating DTO objects, should I put all the properties in DTO itself or wrap the Entity in DTO and add additional properties needed?

Ex: For Edit User Screen,

public class UserDTO
{
     private User user; // User is a JPA entity
     // setters & getters
}

With this I can pass the underlying User entity to my service layer. But while binding UI properties to DTO I need to associate PropertyEditors.

(or)

public class UserDTO
{
    private String userId;
    private String userName;
    private String password;
    // setters & getters
}

With this approach, I need to convert & copy the DTO properties into JPA entities and pass to Service layer.

Which approach is better? Or is there any other approach without DTOs altogether?

  • 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-06-09T09:38:30+00:00Added an answer on June 9, 2026 at 9:38 am

    Your first approach still carries the Entity object itself to the presentation layer. If you have additional parameters that are not coming from the database, and your persistence context is still available, then this approach is sufficient.

    The second approach requires duplication of code, which is not ideal.

    If the persistence context is not available, I would suggest detaching the Entity from the persistence context using EntityManager.detach(), rather than creating a parallel hierarchy of beans.

    On the other hand, if data is coming in from the presentation layer, you will need to load the Entity from the database (using find() or something similar) and update it, or merge() it into the persistence context.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using struts2 for developing a web application. I have include the required
So, i am developing simple web application using Spring Framework. The application users can
I'm developing a simple Android application that would have an action bar on the
I am developing a simple pyramid application where I am using JQuery to do
I'm developing a Grails web application (mainly as a learning exercise). I have previously
I am developing Web Application. In that i am using so many Div to
I am developing a simple web apps that allowed user to key in information
I'm developing a simple JSF application, but I'm stuck again... Basically, I have a
I am developing a simple online suggestion application where the user can fill a
I am developing a spring mvc based application. I have a simple pojo form

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.